我擔心之前可能會提出這個問題,但我沒有找到或不能理解類似問題的答案。JPA OneToOne關係自動創建
我有這樣的一個表offerte
@Entity
public class Offerte extends BaseEntity{
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn(name="dossier")
@GeneratedValue(strategy = GenerationType.AUTO)
@NotNull
private Dossier dossier;
具有OneToOne連接表檔案,並在創建一個offerte我希望有自動卷宗創建的。
@Entity
public class Dossier extends BaseEntity{
@OneToOne(fetch=FetchType.LAZY, mappedBy="dossier")
@NotNull
private Offerte offerte;
我已經試過與generationtype自動做到這一點,但我一直在剛開違反
List of constraint violations:[
ConstraintViolationImpl{interpolatedMessage='may not be null',
是否有可能使這種關係自動有效嗎?
編輯
河提出的Java解決方案
@Entity
public class Offerte extends BaseEntity{
@OneToOne(fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name="dossier")
@NotNull
private Dossier dossier = new Dossier();
提供了以下錯誤
javax.validation.ConstraintViolationException: Validation failed for classes [be.ugent.lca.data.entities.Dossier] during persist time for groups [javax.validation.groups.Default, ]
List of constraint violations:[
ConstraintViolationImpl{interpolatedMessage='may not be null', propertyPath=offerte, rootBeanClass=class be.ugent.lca.data.entities.Dossier, messageTemplate='{javax.validation.constraints.NotNull.message}'}
]
能否請您介紹與列名相關的表? –
你是怎麼表達的@Column(name =「dossier,... annotation?因爲@OneToOne關係不允許這樣做,而且這個關係的兩個列名只是檔案和結果 – turoni
GeneratedValue是非法的在一個關係字段中...它是長,整數,字符串等 –