-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Using detached dirty objects in queries
PostPosted: Mon Aug 02, 2004 8:59 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
In chapter 10.4.2 of the doc, one can read the following:

Each interaction with the persistent store occurs in a new Session. However, the same persistent instances are reused for each interaction with the database. The application manipulates the state of detached instances originally loaded in another Session and then "reassociates" them using Session.update() or Session.saveOrUpdate().

This looks fine until we want to query using one of those objects loaded in a previous session and not yet reassociated with the current one (say because the business transaction is not yet completed).

Example:
The modification of an employee record takes several http requests to complete (long business transaction spanning multiple user requests). We load the employee record at the first request and apply changes to this copy until done. Those changes are not persisted to the database since the employee record is not reassociated with the current session until the end of the business transaction. At the end, changes are persisted using a call to session.update().

Now at some point in the business transaction, we need to search for activities performed by the employee. This information isn't available directly from the employee object so a complex Hibernate HQL query is needed. This query takes the employee as argument.

Unfortunately, this doesn't work seemlessly because the employee is not in the current session.

We could load it by id - but this may cause a duplicate entity in the session if we issue a call to session.update() in the same transaction (see above).


Question is: how can we solve this issue properly ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.