I have two web applications that are running on a single Tomcat server and are connected to the same database with Hibernate. I am concerned that having two SessionFactory instances running around might cause some issues.
Also, since both web applications share much of the same application logic, I thought it would be a good idea to centralize as much as I could. And since I use Spring for DI and Hibernate configuration it would make sense to have a single ApplicationContext as well.
How would I go about doing something like this? Do I need to deploy a headless WAR that creates an ApplicationContext and thus a SessionFactory and allow each application access to it? Is this even a good idea?
It is possible to share the
SessionFactorythrough JNDI (ideally, you would deploy Hibernate in your application server as a JMX-service).But honestly, having 2+
SessionFactoryinstances is not really a concern, there is nothing to really worry about. This is a very common scenario, even for a single application (in a clustered environment).