(Quick Reference)

isAttached

Purpose

Returns whether the domain instance is attached to a currently active Hibernate session. This method is often used on conjunction with the merge or attach methods.

Examples

Book b = session.book
…
if (!b.isAttached()) {
    b.attach()
}

Description

Persistent instances are associated with a persistence Session. A new Session is created for each request and is closed at the end of the request. If an object is read from the session and placed into a web scope such as the HttpSession it is seen as detached, since the persistence session has been closed. You can use the attach method to re-attach an existing persistent instance to the persistence session of the current request.