|
Problems with Hibernnate and Tomcat -
05-27-2011, 08:06 AM
Hi,
I must say first that I am new to Hibernate and the code on which I am working is not written by me.
I am trying to configure an application, the server component of whose uses Hibernate to communicate with the database.
I have changed the config files to suit the configurations in my machine.
When I do a maven clean install of the server project, the test cases get successfully executed and hibernate tests are thus executed which means my configurations are actually correct.
However, After deploying the application to Tomcat, when I make a request to the server which uses hibernate to get data from the database, it throws exception in the HibernateUtil file which has basically the code as this :
private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
return new Configuration().configure().buildSessionFactory(); //// This line throws the exception
}
catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
The stack trace from my log file says :
2011-maj-27 13:26:42 com.sun.jersey.server.impl.application.WebApplicat ionImpl mapMappableContainerException
ALLVARLIG: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
java.lang.ExceptionInInitializerError
at app.server.model.HibernateUtil.buildSessionFactory (HibernateUtil.java:26)
at app.server.model.HibernateUtil.<clinit>(HibernateU til.java:16)
at app.server.user.AndroidUserManager.getUser(Android UserManager.java:24)
at app.server.user.AndroidUserManager.getUser(Android UserManager.java:48)
I have the following dependency for hibernate in my pom.xml
<!-- Hibernate library dependecy start -->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>
<!-- Hibernate library dependecy end -->
My hibernate.cfg.xml is like :
<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">mysql</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/appdb</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MyS QLDialect</property>
<property name="show_sql">false</property>
<mapping resource="Application.hbm.xml"></mapping>
<mapping resource="Category.hbm.xml"></mapping>
<mapping resource="User.hbm.xml"></mapping>
<mapping resource="Permission.hbm.xml"></mapping>
.....................
</session-factory>
</hibernate-configuration>
I am not getting any idea what is going wrong here.
Is there any Tomcat specific settings required here.
Thanks for reading and any help will be highly appreciated.
Thanks and Regards,
Abhiroop
|