-->
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: Caching and the creation of new DB Connections
PostPosted: Tue Jul 17, 2007 4:13 pm 
Newbie

Joined: Tue Jul 17, 2007 3:52 pm
Posts: 3
I am using hibernate for a web based project with lots of referance data which will only change a bit every few days. So, I plan on using the second level cache.

I am using a Session per request. I would like to know when/if hibernate would get a database connection if all I am doing is reading data from the Session which will come from the 2nd level cache?

I am hoping that I can make sure that hibernate will never get a new connection for a read if all the data is in the cache. In order for it to work like this should I not use beginTransaction() and commit() for sessions when I know I will be only reading from the cache?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 18, 2007 6:05 pm 
Newbie

Joined: Tue Jul 17, 2007 3:52 pm
Posts: 3
Hi again,

I can rephrase my question with an example. Any help would be much appreciated.

Consider the example below, with the second level cache in use. The item that is loaded can be obtained from the cache.

Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();

Item item = (Item) session.load( Item.class, new Long(1234) );

tx.commit();
session.close();

I assume that hibernate gets a database connection when session.beginTransaction() is called and not before?

If I know that the data I want is in the second level cache (it is very infrequently updated reference data), then I do not want a db connection taken from the connection pool for this request.

If I dispense with the transaction code in the above snippet, and the session is only used to read data from the cache, will Hibernate make no contact with the database?

Cheers,

Jim


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.