0

I am working with spring hibernate project where a model has a foreign key which mapped with @joincolumn as shown below.

class Customer
{
@JoinColumn(name="CUSTOMER_RM_ID",nullable=true)
@OneToOne(fetch=FetchType.EAGER)
private RmSm customerRMId;
}

But, while saving this entity from angular js UI, via rest api, i am getting below mentioned exception.

Request:

  {"customerRMId":{
    "id":null
    }
}

I have removed all other fields from the model and the request as well, for the readability purpose.

Exception:

org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing:

What is the solution for this, I have tried with hibernate nullable true option. But didn't work!

Vipin CP
  • 3,642
  • 3
  • 33
  • 55
  • It doesn't seem to be a problem with that field. Is there any other fields that hold reference to other entities? is any of these fields populated with a transient object (not yet saved to db, id is null and version is null) – Yazan Jaber Apr 19 '18 at 05:40
  • @YazanJaber no its because of this field only. When i give a value insetad of null it works . – Vipin CP Apr 19 '18 at 05:51
  • Try to add cascade option in @OneToOne, like this one cascade = CascadeType.ALL or SAVE_UPDATE or PERSIST. Depending on your task – Danila Zharenkov Apr 19 '18 at 06:00

0 Answers0