-->
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.  [ 9 posts ] 
Author Message
 Post subject: Read-Only entities
PostPosted: Thu Jul 22, 2004 2:52 pm 
Beginner
Beginner

Joined: Tue Jul 20, 2004 1:53 am
Posts: 43
Location: India
I am using Hibernate 2.1 with ORACLE 8.

In a Hibernate Transaction if I am certain than instances of a particular entity class would be read but never updated, are there any optimizations I can do to hint Hibernate not to bother synching those instances to DB?

In a popular commerical ORM tool I had used, Unit-Of-Work makes available copies of entity instances and the object graphs are 'merged' at commit-time. In that case, there was a provision for the user to specifiy that an entity is never updated within a transaction, so that the tool can ignore merging of instances of that entity.

I am aware that Hibernate maintains a first-level cache that preserves object identity within a Session; so probably such an 'optimization' might not be making sense. Nonetheless, I am curious - can someone more experienced confirm?

_________________
Thanks,
Binil Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 2:56 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Use session.evict(), session.clear(), or HQL projection queries.

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 3:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It's ok, you can say the word "TopLink" here :-)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 3:26 pm 
Beginner
Beginner

Joined: Tue Jul 20, 2004 1:53 am
Posts: 43
Location: India
gavin wrote:
It's ok, you can say the word "TopLink" here :-)


I havent forgotten the dirt the Cocobase guy kicked up ;)

Christian, your seem to suggest that at commit-time Hibernate will have to verify if an entity in first-level cache is "dirty" or not; and hence evicting the entity from the cache will prevent this check. Did I understand you correctly? Please let me know.

_________________
Thanks,
Binil Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 3:28 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Yes, as documented.

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 9:36 am 
Beginner
Beginner

Joined: Tue Jul 20, 2004 1:53 am
Posts: 43
Location: India
Keeping tracking of all instances of a particular class is bit bothersome for me.
If there were a way to get all instances of a particular class from the (first-level-cache of) Session I could have used that, but I could not find such an API.

Is there any neater way to have the effect of read-only-entities without resorting to keeping tracking of all instances manually?

_________________
Thanks,
Binil Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 9:38 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Use projection queries in HQL, ie. a select clause that returns more than one "column".

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 10:42 am 
Beginner
Beginner

Joined: Tue Jul 20, 2004 1:53 am
Posts: 43
Location: India
Hi Chrstian,

Thanks for replying.

The usecase I have in mind is slightly different and can't use projection queries. I load an object graph into memory, perform some operations/modifications on them, and eventaully I commit the transaction. When I commit the transaction, as far as I understand, Hibernate checks if any instance in the object graph is dirty and updates the data in the DB.

While doing this, if I am certain that instances of a particular entity class wont change. I am looking for some API where I can hint Hibernate not to bother checking dirtiness of some portion of the object graph. I expect this to be slightly more performant than the regular way.

I cannot use projection queries here because I dont want the whole object graph to be non-transactional.

I was expecting something like :
Code:
Session session = mySessionFactory.openSession().setReadOnly(MyReadOnlyClass.class);

Kindly advise how to handle such cases.

Thanks again for your time.

_________________
Thanks,
Binil Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 10:54 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Uhm, you could try mutable='false' on the class mapping (or setting it on Configuration before building the SessionFactory). Still, I believe that evict() is probably the granularity you are looking for.

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.