I am working on a solution for this problem: we have multiple web-apps that build a large number of Session Factories (up to 30) with large class maps which are taking up a large amount of space - we have the potential to soon run into memory usage issues if we keep doing this.
We have at least 3 contexts which connect to the same database. Each currently has its own mapping configurations (though we can move to a single mapping configuration) - we did this to help constrain the number of classes we map in each context to help save memory. We have multiple customers, each of which has its own schema in our database and therefore each have their own session factory.
We want to move to an implementation where we create a single set of session factories which may be shared by each of our web apps (basically cutting the number of session factories we have to create by 1/3).
Create a new mapping configuration that is an intersection of all contexts mapping configurations.
Create a new context (named "SessionFactory") that will be responsible for building the session factories.
Set this new context as: crossContext="true"
This new context will have an initialization servlet which will create all needed session factories (using new mapping) and map them to its ServletContext; all other contexts can access as follows:
ServletContext ctx = getServletContext().getContext("SessionFactory");
SessionFactory sf = ctx.getAttribute("<Session Factory ID>");
We are not using Spring, or any other Beans/J2EE frameworks -- just basic web-apps with servlets -- and do not want to (yet)
I have not found any discussions on the proper or accepted way to handle this situation, so I am looking for any known alternatives that would allow our contexts to share session factories between them.
Any insight, potential issues with this solution or alternate (proper) ways to implement this would be greatly appreciated!