maven - hibernate.cfg.xml is not parsed -
i'm working hibernate 4 , maven :
so problem when start sever ,i can't see parsing hibernate.cfg.xml , table not created in database ;
hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-configuration public "-//hibernate/hibernate configuration dtd 3.0//en" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.bytecode.use_reflection_optimizer">false</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.driver</property> <property name="hibernate.connection.password">password</property> <property name="hibernate.connection.url">jdbc:mysql://localhost/mvnodb</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">admin</property> <property name="hibernate.dialect">org.hibernate.dialect.mysqldialect</property> <property name="show_sql">true</property> <mapping class="tn.onp.mvno.model.person" ></mapping> <mapping class="tn.onp.mvno.model.user" ></mapping> <mapping class="tn.onp.mvno.model.call" ></mapping> <mapping class="tn.onp.mvno.model.user" ></mapping> </session-factory>
depending on our setup, hibernate typically started building sessionfactory. unless you're using kind of spring / jpa integration, not automatically happen when start tomcat.
you can utilize next listener initialize , close hibernate on deployment , undeployment.
public class hibernatelistener implements servletcontextlistener { public void contextinitialized(servletcontextevent event) { hibernateutil.getsessionfactory(); // phone call static initializer of class } public void contextdestroyed(servletcontextevent event) { hibernateutil.getsessionfactory().close(); // free resources } }
you'll need have class in classpath, along hibernate jars (+ dependencies_ , database driver.
you'll need configure listener in web.xml
<listener> <listener-class>org.mypackage.hibernatelistener</listener-class> </listener>
if there issues hibernate.cfg.xml file, should see them @ startup.
hibernate maven tomcat
No comments:
Post a Comment