0

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 ?

Rajan Chauhan
  • 461
  • 2
  • 7
  • 18
  • What Run/Debug configuration type do you use in the IDE for running the project? If it is Application one try using [Spring Boot](https://www.jetbrains.com/help/idea/run-debug-configuration-spring-boot.html) instead. – Egor Klepikov Sep 13 '22 at 07:08
  • @EgorKlepikov I am on Intellij community version and run the Application as a Java Application pointing to main class. – Rajan Chauhan Sep 13 '22 at 09:27

0 Answers0