hibernate官方文档(介绍hbm.xml配置的)
If you use Hibernate on Tomcat you don't have to use Tomcat'sJNDI-bound JDBC connections. You can let Hibernate manage the JDBCconnection pool. This works on all versions of Tomcat and is very easyto configure.
First, create a hibernate.cfg.xml or hibernate.propertiesfile, as per documentation (no, property names in cfg.xml don't have tobe prefixed with "hibernate.xxx"):
Now copy this file into your WEB-INF/classes directory ofyour web application. Copy hibernate3.jar into your WEB-INF/libdirectory and with it all required 3rd party libraries (seelib/README.txt in the Hibernate distribution). Don't forget to also copyyour JDBC driver to common/lib or WEB-INF/lib. Neverever copy anything in Tomcat into a global directory outside of yourweb application or you are in classloader hell!
Start Hibernate by building a SessionFactory, as shown here with HibernateUtil.
This listener initializes and closes Hibernate on deployment andundeployment, instead of the first user request hitting the application: