-->
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.  [ 6 posts ] 
Author Message
 Post subject: Criteria.setReadOnly?
PostPosted: Mon Mar 12, 2007 2:55 pm 
Newbie

Joined: Mon Mar 12, 2007 2:45 pm
Posts: 4
Hi all,

A simple question: is it possible to make the results returned from Criteria read-only (i.e., with dirty-checking disabled)?

I'm using Hibernate 3.2 and my Criteria query returns a large number of results which won't be modified but only displayed to the user. I want to tell Hibernate not to create snapshots of all these results for dirty checking. There is a setReadOnly method on the Query interface to achieve just this, but there is no such method on the Criteria interface.

The funny thing is that Java Persistence with Hibernate, 2007 edition, gives an example of using the seemingly unexistent method on page 624..

My Criteria is rather complex, constructed programmatically, so I don't want to use HQL.

Thanks for any hints!


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 4:39 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The method does indeed not exist, my hasty copy/paste error. Added to errata.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 4:54 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
I was having the same question after seeing this in the same tome (great read btw). Is there any plans on adding this? I have the same type of issues, retrieving data that I know I don't want to update at this particular time.

Flushes and dirty checks are killing me, we typically end up calling the save() or update() when we know we're done modifying our entities but that seems to also force flushes even when in MANUAL flushMode. I've got a case right now where I ended up with a few thousands entities in my session yet I've got more than a million and a half calls to the onSaveOrUpdate events firing and the equals methods on all the objects are also getting hammered. I'm seeing those fire even if I simply load up some objects and then commit the transaction even though nothing in the session was modified at all.

Now, I'm currently looking at rewriting this to batch up the process a bit nicer but the code is very tangly and it would be nice in general not to worry about managed objects unless I called save or update.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 6:30 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Ok, while I would still love to have read only support on Criteria I figured out why I was still getting hammered with a MANUAL flushmode.

It would appear I didn't set it early enough in our framework so it didn't get set on the session, oops.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 7:54 pm 
Newbie

Joined: Wed May 23, 2007 6:25 pm
Posts: 7
You can evict anything you want hibernate to forget about.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 8:16 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Yeah, I don't necessarily want to evict it as then I lose any lazy loading no?

Not to mention I'd rather not have to keep going back to the DB to load something that I might have already loaded in the session.


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

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.