I use it on MySQL, it works just fine.
The way I do is with several singletons that have a sessionfactory configured with the correct schema and O/R mapping classes on each.
I handle the two different sessions independently of eachother by having
public final ThreadLocal<Session> currentSessionHolder = new ThreadLocal<Session>();
defined in each of the singletons.
Since I use Spring to manage my singletons, I use an init() and cleanup() method to configure and close open sessions.
For http request cycle handling I register the singletons as ApplicationListeners and implement
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof RequestHandledEvent) {
closeCurrentSessionIgnore();
}
}
Voila, sessions are closed after servlets have handled the requests(provided I configure the proper servletfilter).
Henrik
|