This exception occurs because a transient object is manipulated as a persistent object. The solution of course is to persist the object, you can call the session's save () or the Saveorupdate () method
Here's the science. Hibernate three states in an object:
In a nutshell, that's the way it is,
1. When an object is new, the object is in a transient state (Transient);
2. After the session's save () or Saveorupdate () method is executed on this object, the object is placed in the session's first-level cache into the persistent state.
2. This object enters a Free State (Detached) after the operation of evict ()/close ()/clear () is performed on this object.
4, Free State (Detached) and transient State (Transient) of the object is not managed by the session will be at the appropriate time by the Java garbage Collection station (garbage) recycling.
5, the execution session of Get ()/load ()/find ()/iternte () and other methods from the database to query the object, in a persistent state (persistent).
6, when the record in the database update ()/saveorupdate ()/lock () operation after the free State of the object will transition to the persistent state
7. Objects in persistent State (persistent) and Free State (Detached) have corresponding records in the database.
8, instantaneous State (Transient) and Free State (Detached) objects can be recycled but the instantaneous state of the object in the database does not have corresponding records, and the Free State of the object in the database has a record of use.