-->
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.  [ 5 posts ] 
Author Message
 Post subject: Help required with many-to-one and caching
PostPosted: Wed Feb 27, 2008 6:14 am 
Newbie

Joined: Wed Feb 27, 2008 6:02 am
Posts: 2
Hi All,

I need help on using cache for many-to-one relations.

I have looKup data table which has lookup value. Almost every table in application is linked to Lookup data table and every one has many-to-one relations.

So whenever i load an object, i need to load these Lookup data objects also.

So can i use caching for this solution, as i dont want hibernate to hit the db for each lookup data.

Thanks

Siddharth


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 27, 2008 11:05 am 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
First you need to decide which Second Level Cache provider to use. The reference doc may help you:

http://www.hibernate.org/hib_docs/refer ... ance-cache

The configure the cache settings in your hbm file for class level properties and collection valued properties.


If you are going to use ehcache, then you need to configure ehcache.xml.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 12:46 am 
Newbie

Joined: Wed Feb 27, 2008 6:02 am
Posts: 2
Sorry i might wrongly put the question but,
I am already using the ehcache and configured it, its working for the Collections i.e relation which are one-to-many, but in case on many-to-one its not working. So i need that my look up data which is in many to one relation should be picked from cache.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 9:46 am 
Regular
Regular

Joined: Mon Aug 20, 2007 6:47 am
Posts: 74
Location: UK
snparalikar wrote:
Sorry i might wrongly put the question but,
I am already using the ehcache and configured it, its working for the Collections i.e relation which are one-to-many, but in case on many-to-one its not working. So i need that my look up data which is in many to one relation should be picked from cache.


Make sure that there is a cache region for the class that's the "one" in your ManyToOne.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 10:00 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
You should configure the linked lookup data as Lazy, or "select" mode fetch; othervise it will generate a Join SQL statement. Then when trying to load the linked value with a second separated query it will hit cache.

see http://forum.hibernate.org/viewtopic.php?t=970070


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