我想将运行时生成的实体 UUID 复制到另一个字段。实体 id 是通过下面描述的代码生成的:
package eclipselink.example;
public class UUIDSequence extends Sequence implements SessionCustomizer {
public UUIDSequence() {
super();
}
public UUIDSequence(String name) {
super(name);
}
@Override
public Object getGeneratedValue(Accessor accessor,
AbstractSession writeSession, String seqName) {
return UUID.randomUUID().toString().toUpperCase();
}
...
public void customize(Session session) throws Exception {
UUIDSequence sequence = new UUIDSequence("system-uuid");
session.getLogin().addSequence(sequence);
}
}
持久性.xml:
property name="eclipselink.session.customizer" value="eclipselink.example.UUIDSequence"
实体:
public abstract class MyEntity{
private String id;
private String idCopy;
@Id
@Basic(optional = false)
@GeneratedValue(generator="system-uuid")
@XmlElement(name = "ID")
public String getId() {
return id;
}
}
如何指示 JPA(Eclipse-link)将运行时生成的 UUID 也复制到idCopy
字段中?