Sunday, March 6, 2016

Hibernate Domain/Model/POJO

  1. Default constructor
  2. Has an id(primary key) for identity only, no content meaning for this id
  3. getter/setter

Session methods

  • close()
  • clear(): Completely clear the session
  • connection(): get JDBC connection
  • delete(Object object): Remove a persistent instance from the database
  • evict(Object object): Remove instance from the session cache
  • flush(): force session to flush

Transient state
Object does NOT match any data in the db table
NO session is related to this object
If exceed scope, JVM will do garbage collection.

Normally to be the object has been created but not related to any session nor db record.

Persistent state
Object has matched data in the db table
Object also related to a session
Session is not closed
Transaction is not committed.

If persistent state object changes, the db record will be changed when transaction commited.

//do update db immediately

Detached state
Object has matched data in the db table
Object is NOT related to any session

If detached state object changes, hibernate will not notice that, and db will not change

No comments:

Post a Comment