-->
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.  [ 24 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Cache in Hibernate
PostPosted: Thu May 13, 2004 4:02 pm 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
Based on the documentation, I saw that Session maintains a cache of objects that have been accessed by it. And if you do a closeSession(), the cache is no longer available.

However if you do a session.disconnect() and reconnect(), the cache would be available.

So is it advisable for maintaining the same session for a web-application that may receive concurrent requests so that the cache is maintained?

I also saw that Session is not thread safe and hence should never be shared across threads. If this is the case, say I have a web-applicaiton that may search on a database and it would predominantly be a read-only mode. If I use separate sessions to search for members would'nt that be inefficient in terms of performance?

I also saw a mention of a JVM level cache? Is this by default or does this require additional configuration on the mapping or hibernate.properties.

Thanks,

Anand


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 4:05 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Hibernate has a dual-layer cache architecture. The Session is the first level "transaction" scoped cache and yes, the scope (one request, many requests) can vary. However, the "many requests" scenario is definitely advanced, used for long running "application transactions". The common usage of a Session is one per request/response cycle. The Session cache is mandatory (for transaction integrity) and can not be disabled (you may however evict() objects from the Session if memory consumption is a problem).

The second-level cache is a process- or cluster-scoped cache and optional. Many Sessions can access the second-level cache. For a single VM scenario, put <cache> elements in your mapping files with the appropriate cache concurrency strategy (see documentation) and enable the EHCache provider. Then, set up the ehcache.xml configuration file after you understand how to use cache regions.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 4:28 pm 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
Thanks for the quick tunraround. The documentation does not mentioned anything about EHCache.xml. Is that a separate mapping document for the application to tell EHCache for it's caching strategy.

-Anand


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 4:32 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No, Hibernate can use different cache providers, EHCache is just one of them. After you turn on a specific cache provider (see the configuration settings of Hibernate), you tune the expiration policies and other settings with a provider specific configuration file. An example for EHCache is in the src/ directory of the Hibernate distribution.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 14, 2004 4:12 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
anandbn wrote:
Thanks for the quick tunraround. The documentation does not mentioned anything about EHCache.xml. Is that a separate mapping document for the application to tell EHCache for it's caching strategy.


link from the WIKI area about EHCache using with Hibernate http://www.hibernate.org/158.html
documentation http://www.hibernate.org/hib_docs/reference/en/html/performance.html#performance-cache
EHCache home page http://ehcache.sourceforge.net/

Just now I am experimenting with caches too, and think that caches are documented not too very good :), looking for some more detailed tutorials. Christian, is cache usage described in the "Hibernate in Action"?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 14, 2004 4:37 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Yes, although I don't describe setting up every single cache provider, only EHCache (I'm currently writing a JBossCache tutorial, this will be on the Wiki, not in the book however). What is in the book and very important is the Best Practices about caching, what kind of data is best for caching, the implications for transaction isolation, all with examples.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 14, 2004 12:46 pm 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
Cristian,

project manager bought Manning's Early Access chapters of "Hibernate in Action", now I am waiting for chapter "5. Transactions, concurrency, and caching" :). Please, could you tell when it will be ready to download? Or maybe it is possible to get some excerpts of "Best Practices"?

Leonid


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 14, 2004 12:57 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
It will be available in the next couple of weeks. Sorry, I can't make anything faster.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 08, 2004 10:22 am 
Newbie

Joined: Thu Feb 26, 2004 7:29 am
Posts: 17
hi christian,
have you completed the 'JBossCache tutorial' you mentioned earlier?
i can't seem to find it on the wiki?
cheers,
colum.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 08, 2004 11:13 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Uhm, it ended up in Hibernate in Action...

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 08, 2004 11:17 am 
Newbie

Joined: Thu Feb 26, 2004 7:29 am
Posts: 17
doh, ;-)
if i buy the ebook, does it cover fully how to get JBoss TreeCache working with hibernate??
cheers,
colum.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 08, 2004 11:25 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Yes, but its really not that diffcult: Copy the JARs in your classpath, enable Hibernate caching as documented in the reference, use one of the examples for treecache.xml from the JBossCache distribution.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 08, 2004 12:11 pm 
Newbie

Joined: Thu Feb 26, 2004 7:29 am
Posts: 17
you would think so ;-)
perhaps you could answer two (hopefully easy) questions for me??

1) in the docs it says to set the 'hibernate.transaction.manager_lookup_class'.

From the example treecache.xml files (in the jcache demo zip) i set :
Code:
<attribute name="TransactionManagerLookupClass">org.jboss.cache.DummyTransactionManagerLookup</attribute>

in my jboss-service.xml

Code:
<server>
   <mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateGMMH">
       <depends>jboss.jca:service=RARDeployer</depends>
       <depends>jboss.jca:service=LocalTxCM,name=cjdbc-gmmhDS</depends>
       <attribute name="MapResources">com/yahoo/gmmh/hibernate/PackageType.hbm.xml,com/yahoo/gmmh/hibernate/MobileDevice.hbm.xml,com/yahoo/gmmh/hibernate/Country.hbm.xml,com/yahoo/gmmh/hibernate/Credit.hbm.xml,com/yahoo/gmmh/hibernate/SubscriptionPurse.hbm.xml,com/yahoo/gmmh/hibernate/PaymentAccount.hbm.xml,com/yahoo/gmmh/hibernate/OperatorMap.hbm.xml,com/yahoo/gmmh/hibernate/RegistrationAudit.hbm.xml,com/yahoo/gmmh/hibernate/NotificationPending.hbm.xml,com/yahoo/gmmh/hibernate/ConsumptionRule.hbm.xml,com/yahoo/gmmh/hibernate/SubscriptionType.hbm.xml,com/yahoo/gmmh/hibernate/Service.hbm.xml,com/yahoo/gmmh/hibernate/SchedulerEvent.hbm.xml,com/yahoo/gmmh/hibernate/MobileOperator.hbm.xml,com/yahoo/gmmh/hibernate/PaymentPending.hbm.xml,com/yahoo/gmmh/hibernate/UsageRule.hbm.xml,com/yahoo/gmmh/hibernate/Rate.hbm.xml,com/yahoo/gmmh/hibernate/InvoicePending.hbm.xml,com/yahoo/gmmh/hibernate/MessageDispatch.hbm.xml,com/yahoo/gmmh/hibernate/SubscriptionAudit.hbm.xml,com/yahoo/gmmh/hibernate/PackageRuleAudit.hbm.xml,com/yahoo/gmmh/hibernate/PurchaseRule.hbm.xml,com/yahoo/gmmh/hibernate/PackageTypeAudit.hbm.xml,com/yahoo/gmmh/hibernate/AuthenticationPending.hbm.xml,com/yahoo/gmmh/hibernate/Subscription.hbm.xml,com/yahoo/gmmh/hibernate/ServiceRequest.hbm.xml,com/yahoo/gmmh/hibernate/Invoice.hbm.xml,com/yahoo/gmmh/hibernate/AvailabilityRule.hbm.xml,com/yahoo/gmmh/hibernate/RuleFrequency.hbm.xml,com/yahoo/gmmh/hibernate/MessageType.hbm.xml,com/yahoo/gmmh/hibernate/ReplyPending.hbm.xml,com/yahoo/gmmh/hibernate/UserProfile.hbm.xml,com/yahoo/gmmh/hibernate/SubscriptionTypeAudit.hbm.xml,com/yahoo/gmmh/hibernate/DeliveryNotification.hbm.xml,com/yahoo/gmmh/hibernate/CommandType.hbm.xml,com/yahoo/gmmh/hibernate/DeviceRuleAudit.hbm.xml,com/yahoo/gmmh/hibernate/MessageReply.hbm.xml,com/yahoo/gmmh/hibernate/SessionMap.hbm.xml,com/yahoo/gmmh/hibernate/SubscribeRule.hbm.xml,com/yahoo/gmmh/hibernate/DispatchCredit.hbm.xml,com/yahoo/gmmh/hibernate/Promotion.hbm.xml,com/yahoo/gmmh/hibernate/SubscriptionRuleAudit.hbm.xml,com/yahoo/gmmh/hibernate/PurchaseAudit.hbm.xml,com/yahoo/gmmh/hibernate/RuleSchedule.hbm.xml,com/yahoo/gmmh/hibernate/Package.hbm.xml,com/yahoo/gmmh/hibernate/RateCategory.hbm.xml</attribute>
       <attribute name="JndiName">java:/hibernate/gmmh</attribute>
       <attribute name="Datasource">java:/cjdbc-gmmhDS</attribute>
       <attribute name="Dialect">net.sf.hibernate.dialect.MySQLDialect</attribute>
       <attribute name="UseOuterJoin">true</attribute>
       <attribute name="ShowSql">true</attribute>
       <attribute name="UserTransactionName">UserTransaction</attribute>
       <attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
       <attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
       <attribute name="CacheProvider">net.sf.hibernate.cache.TreeCacheProvider</attribute>
       <attribute name="TransactionManagerLookup">org.jboss.cache.DummyTransactionManagerLookup</attribute>

   </mbean>

</server>


but when i deploy my hibernate sar this gives me an exception :

org.jboss.deployment.DeploymentException: No Attribute found with name: TransactionManagerLookup

i've also tried setting the attribute name to 'hibernate.transaction.manager_lookup_class' but that didn't work (obviously).

question is, what is the exact attribute name to use???

2) in the example treecache.xml files they set the TransactionManagerLookup class to org.jboss.cache.DummyTransactionManagerLookup.
I assume this is just an example and shouldn't be used in a production system.??

what should the value be set to??

is it : 'JBossTransactionManagerLookup'

thanks for your quick responses,
colum.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 08, 2004 12:13 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You don't have to set the treecache.xml lookup class, its for JBossCache outside of Hibernate. Set the Hibernate configuration, it will tell JBossCache what to do.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 08, 2004 12:19 pm 
Newbie

Joined: Thu Feb 26, 2004 7:29 am
Posts: 17
do you mean, not to set it in the treecache.xml but still set it in the hibernate jboss-service.xml???
or should it not be set in either?

cheers,
colum.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 24 posts ]  Go to page 1, 2  Next

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.