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