-->
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: Help configuring cache dynamically
PostPosted: Wed Sep 27, 2006 2:02 pm 
Beginner
Beginner

Joined: Thu Aug 18, 2005 4:34 pm
Posts: 33
Hi, I use Hibernate 3.1.3.

I have a common code base for a schema most apps use. It's slapped in a JAR. So I don't use any hibernate.cfg.xml file.

I'm trying to get second level caching to work. I'm following this tutorial

http://www.devx.com/dbzone/Article/29685/

I've put the <cache/> statement in some of my .hbm.xml files. Now I need some help.

Here's how my hibernate is currently setup at runtime :


Code:
// Create the SessionFactory
SessionFactory sessionFactory = null;
Configuration toolConfiguration = new Configuration();
     
String datasourceName = "jdbc/publicommon";
     
     
toolConfiguration.setProperty("hibernate.connection.datasource", datasourceName);
toolConfiguration.setProperty("hibernate.dialect", "org.hibernate.dialect.OracleDialect");
toolConfiguration.setProperty("hibernate.show_sql", "false");
// Caching
toolConfiguration.setProperty("hibernate.max_fetch_depth", "3");
      toolConfiguration.setProperty("hibernate.cache.use_second_level_cache", "true");
toolConfiguration.setProperty("hibernate.cache.use_query_cache", "true");
toolConfiguration.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.EhCacheProvider");
     
     
     
      File commonJar = new File(pathToWebApp + "/WEB-INF/lib/pct.jar");
      toolConfiguration.addJar(commonJar);
      log.info("Trying to read PCT Hibernate information from " + pathToWebApp + "/WEB-INF/classes/ca/gc/publiservice/commontools/web/hibernate");
      toolConfiguration.addDirectory(new File(pathToWebApp + "/WEB-INF/classes/ca/gc/publiservice/commontools/web/hibernate"));
      sessionFactory = toolConfiguration.buildSessionFactory();
     
      HibernateUtil.setSessionFactory(sessionFactory);
      log.info("Session factory is set.");
     


It works beautifully. And as you can see, I've started to set my second level cache information. Here's my questions

- ehcache.xml, where should I put this? I guess I will try to put it in /WEB-INF/ca/gc....../web/hibernate?

- The real stumper : How do I set the tags that are supposed to go in hibernate.cfg.xml? I don't have a file like this since it's all done at runtime.


Thanks for the help!
Greg


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.