A detached object is one that has been persistent, but its Session has been closed.
For example:
Code:
Session session = factory.openSession();
MyEntity myEntity = null;
Transaction tx;
try {
tx = session.beginTransaction();
//do some work
entity = session.get(MyEntity.class, new Long(12345));
...
tx.commit();
} catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
} finally {
session.close();
}
// myEntity is now a detached instance
System.out.println(myEntity.getFoo());
For more info on different stats of persistent objects, see this page:
http://www.hibernate.org/hib_docs/reference/en/html/objectstate.html