-->
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: Bypassing the Hibernate cache in the same session....
PostPosted: Mon Nov 29, 2004 1:56 pm 
Newbie

Joined: Fri Nov 19, 2004 7:29 am
Posts: 2
Location: United Kingdom
Hibernate version: 2.1.1

Name and version of the database you are using: Db2 v8.1.7


I have an issue with attempting to selectively bypass the Hibernate first level cache using LockMode.READ withing the same Hibernate session. I have a simple test method as follows: -

public void testAdapter() throws Exception
{
long orgId = 1;
// Start up hibernate session.
hibernateAccess = new DataAccessBase();
hibernateAccess.startUpHibernate();
hibernateAccess.setHibernateOrganisationGroup(orgId);
dbsession = DbSession.getInstance();

try
{
long id = 1;
Vendor s1 = (Vendor) dbsession.load(Vendor.class, id);

Vendor s2 = (Vendor) dbsession.load(Vendor.class, id, LockMode.UPGRADE);

}
catch (HibernateException e)
{
e.printStackTrace();
}
dbsession.closeSession();
}

DbSession forms a wrapper around a Hibernate session and provides the same functionality in terms of method availability.

When I run the above code the first session.load accesses the database ( I can see this with show_sql - true ). When the second session.load executes it does NOT access the database even though I have specified a LockMode of READ. Instead it retrieves the object from the first level Hibernate cache.

As I have not specified a LockMode for the first session.load I expected it to execute with a LockMode.NONE. It does this up to a point but when it stores the retrieved object in the cache, Hibernate associates it with a Lockmode of READ. Then when the second session.load executes it has a LockMode that equals the LockMode of the first session.load.

The Hibernate code that performs this association seems to be in method instanceNotYetLoaded in class net.sf.hibernate.loader.Loader.java

My question is - Is this a Hibernate bug or a lack of understanding on my part? The Hibernate in Action book states that using LockMode.READ will "Bypass both levels of the cache, and perform a version
check to verify that the object in memory is the same version that currently
exists in the database". The main goal of all of this is to use managed versioning. We implement managed versioning and I want to be able to retrieve the latest available object directly from the database for use in version number comparison.

Ps I have read the Hibernate manual and Hibernate In Action until my eyes have bled. However, I feel the documentation in the area of the first level cache and how to interact with it / bypass it is a bit misleading.


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.