Not-null property references a transient value - transient instance must be saved before current operation
Try putting CascadeType.ALL
@OneToOne(fetch = FetchType.EAGER,cascade=CascadeType.ALL)
@JoinColumn(name="COUNTRY_ID", nullable=false)
private Country country;
I had a similar problem. Two entities: Document and Status.
Document had a relationship OneToMany
with Status, that represented the history of Status the Document had.
So, there was a @NotNull
@ManyToOne
reference of Document inside Status.
Also, I needed to know the actual Status of Document. So, I needed another relationship, this time @OneToOne
, also @NotNull
, inside Document.
The problem was: how can I persist both entities the first time if both had a @NotNull
reference to the other?
The solution was: remove @NotNull
reference from actualStatus
reference. This way, it was able to persist both entities.