Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java org.hibernate.MappingException:需要AnnotationConfiguration实例_Java_Hibernate_Jar - Fatal编程技术网

Java org.hibernate.MappingException:需要AnnotationConfiguration实例

Java org.hibernate.MappingException:需要AnnotationConfiguration实例,java,hibernate,jar,Java,Hibernate,Jar,我有个冬眠的问题 我使用IntelliJ作为IDE,在配置Web模块和Hibernate模块后,我的代码下面的标题中出现了问题: private static SessionFactory configureSessionFactory() throws HibernateException { Configuration configuration = new Configuration(); configuration.configure(); serviceRegi

我有个冬眠的问题

我使用IntelliJ作为IDE,在配置Web模块和Hibernate模块后,我的代码下面的标题中出现了问题:

private static SessionFactory configureSessionFactory() throws HibernateException {
    Configuration configuration = new Configuration();
    configuration.configure();
    serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    return sessionFactory;
}

public static SessionFactory getSessionFactory() {
    return configureSessionFactory();
}
在hibernate cfg下面:

<?xml version='1.0' encoding='utf-8'?><!DOCTYPE hibernate-onfiguration PUBLIC    "-//Hibernate/Hibernate Configuration DTD//EN"    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration>  <session-factory>
<property name="connection.url">jdbc:mysql://localhost:3306/mydb</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">rugby82</property>
<mapping class="DataBase.Hibernate.Device"/>
<mapping resource="DataBase/Hibernate/Device.hbm.xml"/>
<mapping class="DataBase.Hibernate.Measurement"/>
<mapping resource="DataBase/Hibernate/Measurement.hbm.xml"/>
<mapping class="DataBase.Hibernate.User"/>
<mapping resource="DataBase/Hibernate/User.hbm.xml"/>
<!-- DB schema will be updated if needed -->
<!-- <property name="hbm2ddl.auto">update</property> -->

jdbc:mysql://localhost:3306/mydb
com.mysql.jdbc.Driver
根
橄榄球82

下面是我的依赖关系:

antlr-2.7.6.jar

aopalliance-1.0.jar

commons-collections-3.1.jar

dom4j-1.6.1.jar

ejb3-persistence-1.0.2.GA.jar

guice-2.0.jar

hibernate-annotations-3.4.0.GA.jar

hibernate-commons-annotations-3.1.0.GA.jar

hibernate-core-3.3.0.SP1.jar

hibernate-entitymanager-3.4.0.GA.jar

javassist-3.4.GA.jar

jta-1.1.jar

log4j-1.2.14.jar

mysql-connector-java-5.1.35.jar

slf4j-api-1.5.10.jar

slf4j-log4j12-1.5.10.jar

sli4j-core-2.0.jar

sli4j-slf4j-log4j-2.0.jar

xml-api-1.0.b2.jar

IDE是否可能找不到hibernate.cfg.xml文件? 有什么想法吗

我还想指定在调用DB上的查询时发生的问题。。。
我确实知道为什么如果我开发一个测试类以便在DB上执行查询(因此不是从servlet),它似乎工作得很好……

使用类注释配置而不是配置来配置sessionFactory

sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();

在登录Servlet中显示异常的完整堆栈跟踪,从用户选择*from User where User='giulio'和Password='ru2'log4j:WARN找不到记录器的附加器(org.hibernate.cfg.Environment)。log4j:警告请正确初始化log4j系统。org.hibernate.MappingException:使用mag 02,2015 2:17:01 PM org.apache.catalina.startup.HostConfig部署目录信息需要AnnotationConfiguration实例i:Deploying web application directory/home/empty/Tomcat7/webapps/managernothing…我还想指定在调用查询时引发异常。。。