I am struggling with an issue in Intellij where I have a Spring Boot JPA-Hibernate project and have a model class TransitDeclaration which has @OneToOne
mapping with another entity Consignment, I have other entities there in the project as well like Document, Address, Parties, etc. The issue is whenever I do a change like changing the name of any property in an entity or changing their JPA mappings or adding a new property I get the below error -
not-null property references a null or transient value : mypackage.model.consignment.Consignment.declaration; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value : be.fgov.minfin.ncts.td.domain.model.consignment.Consignment.declaration
Mapping of my TransitDeclaration and Consignment entity -
TransitDeclaration.java
@OneToOne(
mappedBy = "declaration",
cascade = {CascadeType.ALL})
@JsonManagedReference("Consignment_Declaration")
@Valid
private Consignment consignment;
Consignment.java
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "TD_ID", nullable = false)
@JsonBackReference("Consignment_Declaration")
@EqualsAndHashCode.Exclude
private TransitDeclaration declaration;
However when I do a clean install this error goes away and Application runs as expected. My Question is if it's a JPA-Hibernate Mapping related issue (Which I am sure is not as I have debugged the application several times and I have all the associated reference entities available) then how come clean install resolves it ? Or do I need to configure the mapping in some other way around ?