0
我有兩個實體是這樣的(第二個與第一個關係):JPA和子類ID合併
@Entity
@Table(name="FOA_ADRESSE_ICX")
public class FoaAdresseIcx implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="ID_ADRESSE", unique=true, nullable=false, precision=5)
private long idAdresse;
@Column(length=32)
private String bat;
@Column(name="COD_POSTAL", length=5)
private String codPostal;
// getters and setters ....
}
@Entity
@Table(name="FOA_INFOS_ICX")
public class FoaInfosIcx implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="COD_ICX", unique=true, nullable=false, length=8)
private String codIcx;
@Column(name="DATE_RAFFRAICHISEMENT")
@Temporal(TemporalType.TIMESTAMP)
private Date dateRaffraichisement;
@Column(name="LIB_AGENCE", nullable=false, length=98)
private String libAgence;
//uni-directional many-to-one association to FoaAdresseIcx
@ManyToOne
@JoinColumn(name="ID_ADRESSE", nullable=false)
private FoaAdresseIcx foaAdresseIcx;
// getters and setters....
}
我得到的合併問題:
myEntityMgr.merge(myFoaInfosIcx);
得到這個例外:
GRAVE: EJB Exception: : javax.persistence.EntityNotFoundException: Unable to find com.groupama.middlgan.entities.FoaAdresseIcx with id 0
在myFoaInfosIcx
id爲0,因爲我不初始化它,因爲我想JPA創建新FoaAdress數據庫中的eIcx如果不存在。
我該怎麼做?