I'm working on a webapp that uses JPA and Hibernate, deploying it on Tomcat. Things are moving along nicely, but I have one ongoing problem that is very frustrating.
Whenever I undeploy my webapp, Tomcat leaves behind the "hibernate-entitymanager.jar" file in the "webapps\myapp\WEB-INF\lib" directory. That means I have to shutdown Tomcat entirely, manually delete the "webapps\myapp" directory and the "work\Catalina\localhost\myapp" directory, then restart Tomcat and FINALLY deploy the new version of my webapp.
The problem is that Tomcat has a lock on the hibernate-entitymanager.jar file. I've set in the "conf\context.xml" file, but that hasn't solved the problem.
Presumably, I'm failing to close something in my code, which is causing the lock, but I can't imagine what.
Here's MyFactory.java, which creates an EntityManagerFactory, as well as EntityManagers:
Here's MyListener.java, which causes MyFactory to create the EntityManagerFactory when the webapp is first deployed, rather than waiting until the users access it:
Somewhere in my web.xml file, a line to cause MyListener to do its thing:
Even if I deploy my webapp, then without ever accessing it, try to undeploy it, Tomcat is still unable to delete hibernate-entitymanager.jar. Why? The MyListener class ran and initalized the EntityManagerFactory, but that's presumably all that has happened. When I tried to undeploy, presumably the EntityManagerFactory's close method was called. Since it never actually called anything else, I can't have forgotten to close something (e.g. a session).
What am I missing?
I'm using Hibernate 3.2, Tomcat 5.5, JDK 1.5, JSF 1.1. Also, in case it matters, I'm using JPA annotations (@Entity, @Table, @Column, etc). I'm using a persistence.xml file and a hibernate.properties file, but no hibernate.cfg.xml file.
Actually, just in case it matters, here's the persistence.xml file: