-->
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: setting autocommit causes strange cache behaviour
PostPosted: Thu Jan 13, 2005 12:20 pm 
Newbie

Joined: Fri Nov 26, 2004 5:11 am
Posts: 5
Hibernate version: 2

I am investigating a problem with an application which is using the 'detached objects' strategy within a web application.

The problem is that although a call to close the session is made - it appears that the cache is not cleared. Thus when a subsequent call is made, the contents of the cache are returned - not reflecting any changes which may have been made to the database (another process updates one of the tables).

I have tracked down the problem to a call:

m_Session.connection().setAutoCommit(false);

This is called after the session is retrieved from the factory.

I realise that Hibernate automatically sets autocommit to false on retrieval from a connection pool, so this code is not necessary - but I would like to know what is actually happening within my application?

Thanks for any help

Neil.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 5:19 pm 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
Sounds like you need to understand the difference between the first and second level cache. The first level cache is local to the Hibernate session and contains actual materialized objects. The second level cache is global and exists outside the scope of a single session. Also, the second level cache contains rowset data, not materialized objects. If you set up your caching to cache absolutely everything it is very feasible that you could run out of memory, especially if your JVM is set to a low amount of memory.

First, go read about the hibernate first and second level cache in the documentation and in "Hibernate in Action." Also read up on them in the FAQ.

Second, try analyzing your application to identify exactly what really needs to be cached. Some things don't require it, and SOME things should NEVER be cached. I have an object structure that could result in litterally millions of rows being cached if I marked it's entity class as cached.

Third, verify that your JVM's heap size is set to an appropriate level. It's amazing how many people don't know that their JVM defaults to a maximum heap size of 64 MB, which is completely inapropriate for a caching J2EE app. I recommend increasing the heap size to about 70% of available system memory on a dedicated server.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 5:20 pm 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
Sounds like you need to understand the difference between the first and second level cache. The first level cache is local to the Hibernate session and contains actual materialized objects. The second level cache is global and exists outside the scope of a single session. Also, the second level cache contains rowset data, not materialized objects. If you set up your caching to cache absolutely everything it is very feasible that you could run out of memory, especially if your JVM is set to a low amount of memory.

First, go read about the hibernate first and second level cache in the documentation and in "Hibernate in Action." Also read up on them in the FAQ.

Second, try analyzing your application to identify exactly what really needs to be cached. Some things don't require it, and SOME things should NEVER be cached. I have an object structure that could result in litterally millions of rows being cached if I marked it's entity class as cached.

Third, verify that your JVM's heap size is set to an appropriate level. It's amazing how many people don't know that their JVM defaults to a maximum heap size of 64 MB, which is completely inapropriate for a caching J2EE app. I recommend increasing the heap size to about 70% of available system memory on a dedicated server.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 5:29 pm 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
Sounds like you need to understand the difference between the first and second level cache. The first level cache is local to the Hibernate session and contains actual materialized objects. The second level cache is global and exists outside the scope of a single session. Also, the second level cache contains rowset data, not materialized objects. If you set up your caching to cache absolutely everything it is very feasible that you could run out of memory, especially if your JVM is set to a low amount of memory.

First, go read about the hibernate first and second level cache in the documentation and in "Hibernate in Action." Also read up on them in the FAQ.

Second, try analyzing your application to identify exactly what really needs to be cached. Some things don't require it, and SOME things should NEVER be cached. I have an object structure that could result in litterally millions of rows being cached if I marked it's entity class as cached.

Third, verify that your JVM's heap size is set to an appropriate level. It's amazing how many people don't know that their JVM defaults to a maximum heap size of 64 MB, which is completely inapropriate for a caching J2EE app. I recommend increasing the heap size to about 70% of available system memory on a dedicated server.


Top
 Profile  
 
 Post subject: No 2nd level cache defined
PostPosted: Fri Jan 14, 2005 5:40 am 
Newbie

Joined: Fri Nov 26, 2004 5:11 am
Posts: 5
I have read the the excellent Hibernate book you have mentioned - and unless I have mis-understood the concepts we are not caching anything. We have not defined a caching strategy for any of the objects - therefore there is no second level cache.

I am also not sure how the auto commit flag would affect a caching strategy even if it was in place?

Neil.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 17, 2005 1:45 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you should provide a small testcase showing you problem

_________________
Emmanuel


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.