[Solved] Object references an unsaved transient instance – save the transient instance before flushing

1. Exception: org.hibernate.transientobjectexception: object references an unsaved transient instance – save the transient instance before flushing:

This is mainly encountered during the manytoone cascade operation. For example, a new object is saved into a new new object before it is saved (that is, it is not persistent)

The solution is to find out the object before saving or updating (this is a persistent state)

The solution is to set the cascade of many-to-one as: cascade = “save update, persist”

Four cascade types:
* persistent: when the owner entity is persisted, all related data of the entity will also be persisted
* merge: when a detached entity is re merged into the persistence context of an activity, all relevant data of that entity will also be merged
* remove: when an entity is deleted, all related data of the entity will also be deleted
* all: all of the above are applicable

2. Exception 1: not nullproperty references anullortransientvalue
solution: set not null to false for the “one” party in the “one to many” relationship

Exception 2: org. Hibernate. Transientobjectexception: object references an unsaved transient instance
solution: cascade = “save update, persist”

Exception 3: org. Hibernate. Queryexception: could not resolve property
solution: “from category category where category. Userid =: userid” is modified to “from category where userid =: userid” or “from category category where category. User. Id =: userid”

Exception 4: could not initialize proxy – the owning session was closed
solution: set lazy to false

Similar Posts: