Friday, 21 August 2020

Caused by: org.hibernate.TransientObjectException:

 Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.ynz.demobasicauthentication.entities.User



I met the same Exception, as handling many to many relationships.

my case is a user has many roles, while a role has many users.

the exception Is due to as persisting user, but its associated roles that haven’t been saved in the base; so the PK is not present. so the relationships cannot be built up.


solution:   I added cascade type then the exception was solved. 

@ManyToMany(cascade = CascadeType.PERSIST)








No comments:

Can Jackson Deserialize Java Time ZonedDateTime

Yes, but must include JSR310. Thus ZonedDateTime can be deserialized directly from JSON response to POJO field. <dependency> <g...