未分析hibernate.cfg.xml
我正在使用hibernate 4和Maven: 所以问题是,当我启动服务器时,我无法看到它解析hibernate.cfg.xml 并且该表未在数据库中创建 hibernate.cfg.xml未分析hibernate.cfg.xml,hibernate,maven,tomcat,Hibernate,Maven,Tomcat,我正在使用hibernate 4和Maven: 所以问题是,当我启动服务器时,我无法看到它解析hibernate.cfg.xml 并且该表未在数据库中创建 hibernate.cfg.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hib
<?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>
假的
com.mysql.jdbc.Driver
密码
jdbc:mysql://localhost/mvnodb
根
管理
org.hibernate.dialogue.mysqldialogue
真的
根据我们的设置,Hibernate通常通过构建SessionFactory来启动。除非您使用某种Spring/JPA集成,否则在启动tomcat时不会自动发生这种情况 您可以使用以下侦听器在部署和取消部署时初始化和关闭Hibernate
public class HibernateListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
HibernateUtil.getSessionFactory(); // Just call the static initializer of that class
}
public void contextDestroyed(ServletContextEvent event) {
HibernateUtil.getSessionFactory().close(); // Free all resources
}
}
您需要在类路径中包含此类,以及hibernate JAR及其依赖项和数据库驱动程序
您还需要在web.xml中配置侦听器
<listener>
<listener-class>org.mypackage.HibernateListener</listener-class>
</listener>
org.mypackage.HibernateListener
如果您的hibernate.cfg.xml文件有问题,您应该在启动时看到它们。您有两个属性
hibernate.connection.password
。服务器日志中是否有异常?