我有ID的课程
@org.hibernate.annotations.AccessType("property")
public class ObjectID implements java.io.Serializable
{
private long value;
long getValue()
{
return value;
}
void setValue(Long id)
{
value = id != null ? id : 0L;
}
// equals, hash, contructor
}
已映射使用此ID类的类(患者)。我想在ObjectID类中生成long值。帮帮我 我试过了
public class Patient implements Serializable
{
@javax.persistence.Id
@javax.persistence.Column(name = "aa_id")
@org.hibernate.annotations.Formula("case when aa_id is null then patient_seq.nextval else aa_id end")
@javax.persistence.AttributeOverride(name = "value", column = @Column(name = "aa_id"))
private ObjectID id;
}
和
public class Patient implements Serializable
{
@javax.persistence.Id
@javax.persistence.SequenceGenerator(name = "PatientSequenceGenerator",
sequenceName = "patient_seq")
@javax.persistence.GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = "PatientSequenceGenerator")
@javax.persistence.AttributeOverride(name = "value", column = @Column(name = "aa_id"))
private ObjectID id;
}
但是没有帮助
解决此问题的方法之一是为ObjectID编写自定义userType并编写自定义ID生成器。
答案 0 :(得分:0)
compositeIds通常由程序分配,我不知道是否有可能通过开箱即用的数据库序列设置它(或部分)。
首先你可以尝试这样设置它是否有效:
public class Patient implements Serializable
{
@Id
@SequenceGenerator(name = "PatientSequenceGenerator", sequenceName = "lab_patient_seq")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PatientSequenceGenerator")
private Long id;
}