Transient: The object just new
Persistent:sava or post-update status
After Detached:close or clear
Test function:
@Testpublic void Testsavewith3state () {Teacher t = new Teacher (); T.setname ("T1"); T.settitle ("Middle"); T.setbirthdate ( New Date ()); At this time t is the transient state session session = Sessionfactory.getcurrentsession (); Session.begintransaction (); Session.save (t); System.out.println (T.getid ()); This is the persistent state session.gettransaction (). commit (); System.out.println (T.getid ()); This is the detached state}
3 kinds of states of distinction:
1. Is there an ID?
2. Is the ID in the database?
3. ID in memory?
Transient: An object in memory, no ID, no cache.
Persistent: In memory, slow to exist, database has, ID
Detached: Inside, cache No, database has, ID
Three states of the hibernate--object transient,persistent,detached