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:
Post a Comment