-->
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.  [ 2 posts ] 
Author Message
 Post subject: Evict object from session cache by ID (without select)
PostPosted: Sat Jun 18, 2005 3:23 pm 
Beginner
Beginner

Joined: Thu Mar 03, 2005 9:19 pm
Posts: 22
Hello,
There are two ways to update the datafield of an object A:
1. A = session.get(A.Class, aId);
A.setDataField(...)
session.saveOrUpdate(A)

2. session.createQuery("update A set field1=... where aId=..")

Method 1 generates 1 select and 1 update

Method 2 generates 1 update.

However, although Method 2 looks more efficient, it does not hadnle session cache or second level cache automatically. So you have to manually evic the cached instance.

For second level cache, you can do sessionfactory(A.class, aId);
However, I do not know how to evict an object from session (first level cache) without a select. There is a method: session.evict(Object obj), but you have to have the object first.

So in conclusion, I have two questions:
1. For method 2, is there a way to evict an object without first do a select? Something like, sessionFactory.evict(A.class, aId). Please note that the assumption is, you do not know wether this object is in session cache or not. If it does resides in session cache, you need to evict. If not, you don't have to do anything.

2. For method 1, if 2nd level cache is used, do we have to call sessionfactory(A.class, aId) or Hibernate will handle this for us automatically?

I read the cache chaper in both HIA and Reference but could not find answer.

Thanks,

Joe


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 22, 2005 7:31 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
1. on a lazy object, s.load(MyClass.class, id); will not do a select.
2. yes it does in a transactional manner. Wich is not the case of your manual eviction.

_________________
Emmanuel


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