I have been trying to figure out a way to create shared Hibernate session service on Tomcat 6. basically, I need to have this service: 1. to be re-deployable (which exclude the JNDI service); 2. all the web applications can share the same Hibernate sessions (cache). The Tomcat class loading mechanism seems make sharing the db sessions impossible. I could create a web application with the Spring HttpInvoker which can be used by other web applications. Or I could go with the Spring dm-Server but it seems the complexity of the solution would comparable to that of an application server (JBoss or Glassfish). What would be the viable solution?
+1
A:
You can use the 2nd level cache
Apart from that - let's assume you want to modularize you application and that's the reason for having two (or more) webapps. But if you want to cache entities from two different webapps, that means the same entity classes exist in both. Which by itself isn't that wrong, but having the same cache for these entities in different contexts seems wrong. Perhaps you don't need two web apps after all?
If you are certain that you need this, you can try implementing a custom Tomcat valve, but I can give you neither recommendations nor details about it.
Bozho
2010-01-15 06:49:46
The Tomcat valve is an interesting idea. I will definitely check it out. The practice itself is not quite elegant anyway. We are looking at multiple GWT web applications to share one Hibernate sessionfactory. Thanks.
renfred
2010-01-15 19:29:43