This content has been marked as final.
Show 3 replies
-
1. Re: reasociating detached entities (non smpc)
jacob.orshalick Sep 14, 2007 2:22 PM (in response to cba2)If it is okay to copy the state of the given object onto the persistent object with the same identifier, the following will do the trick:
... attachedEntity = myHibernateSession.merge(detachedEntity); ...
Be aware of the semantics of the merge operation defined by JSR-220.
Otherwise, you could simply do a fetch join when you retrieve the object initially to also retrieve required dependencies. -
2. Re: reasociating detached entities (non smpc)
cba2 Sep 17, 2007 4:07 AM (in response to cba2)Thanks for the hint, jacob.orshalick. Actually, the problem is however not about re-associating a single know entity to the new session but rather about re-associating all entities in the current long running transaction. So the challenge is much rather how to find / enumerate all entity objects that exist in the current transaction.
btw: I already knew session.merge() and a few other hibernate tricks that re-associate a single entity, but a "grep" through the Seam source (Seam2.0.0.BETA1) had shown me that Seam does not actually use merge() to achieve the goal even before I started this thread. -
3. Re: reasociating detached entities (non smpc)
wschwendt Sep 17, 2007 5:51 AM (in response to cba2)"cba2" wrote:
What is the easiest way to manually re-associate all detached entities in my conversation with the new session of the current request? I tried to study the Seam source code but did not discover which trick Seam uses to achieve this so smoothly an transparent.
Seam supports the concept of a Seam-managed conversation-scoped persistence context, which is an extended persistence context whose lifetime is tied to the lifetime of a conversation.
If such a Seam-managed persistence context is used, Entities don't get detached between requests but stay managed as long as the conversation (or application transaction) lasts.
See chapter "Chapter 8. Seam and Object/Relational Mapping", section
"8.3. Seam-managed persistence contexts" of the reference manual for more information.