Book b = session.book
...
if (!b.isAttached()) {
b.attach()
}
isAttached
Purpose
Examples
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.