1
votes

i hava a problem with hibernate.

I use IntelliJ as IDE and after configure the Web module and Hibernate module i get the issue in the title...below my code:

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();
}

below the 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> -->

below my dependency:

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-apis-1.0.b2.jar

it is possible that the hibernate.cfg.xml file is not found by the IDE? any IDEA?

i want also specify that the problem happen when i call a query on DB... i do know why if i develop a test class in order to execute a query on the DB (thus not from a servlet) it seems working fine....

1
show complete stacktrace of the exceptionChaitanya
In the Login Servlet select * from User where User='giulio' AND Password='ru2' log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment). log4j:WARN Please initialize the log4j system properly. org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="DataBase.Hibernate.Device"/> mag 02, 2015 2:17:01 PM org.apache.catalina.startup.HostConfig deployDirectory INFORMAZIONI: Deploying web application directory /home/empty/Tomcat7/webapps/managerrugby82

1 Answers

0
votes

Use the class AnnotationConfiguration instead of Configuration to configure your sessionFactory.

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

Check this