-1
我正在使用休眠4.3.8。在Java Spring Web應用程序和postgres數據庫中。用現有記錄的外鍵創建休眠實體
我有兩個外鍵記錄中的記錄B和C.
記錄B已經存在於系統中。 記錄C是新的,當我保存記錄A時將被添加。記錄A佈局就是這樣。
A.primaryKey
A.foreignKey to B.primaryKey (already exists in system)
A.foreignKey to C.primaryKey (new record)
A.feildX
如何保存記錄A?
感謝您的幫助
這裏是classes.I是新冬眠這也解釋了錯誤的實體。
@Entity
@Table(name="atable")
public class Aclass {
@Id
@Column(name="arec_id")
private String id;
//Do not create a reference to the bclass in this object. however do write the bclass object with a foreign key reference back to this aclass object
? @Transient
? @OneToOne(cascade=?)
? @JoinTable(name="btable",[email protected](name="brec_id"))
? private Bclass bclass;
//Create a reference to the cclass object in this record and write the cclass object as well
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="crec_foreign_key",referencedColumnName="crec_id")
private Cclass cclass;
@Column(name="description")
private String description;
private VoiceEngineModel voiceEngineModel;
}
@Entity
@Table(name="btable")
public class Bclass {
@Id
@Column(name="brec_id")
private String id;
@Column(name="aref")
private String aref;
@Column(name="description")
private String description;
}
@Entity
@Table(name="ctable")
public class Cclass {
@Id
@Column(name="crec_id")
private String id;
@Column(name="description")
private String description;
}
郵報你的實體類以及你的持久性代碼的源代碼,如果你有的話還沒有 –