aspose file tools*
The moose likes Spring and the fly likes hibernate 4 and spring 3.1.2 issue with LocalSessionFactoryBuilder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "hibernate 4 and spring 3.1.2 issue with LocalSessionFactoryBuilder" Watch "hibernate 4 and spring 3.1.2 issue with LocalSessionFactoryBuilder" New topic
Author

hibernate 4 and spring 3.1.2 issue with LocalSessionFactoryBuilder

fabian verbeek
Ranch Hand

Joined: Oct 20, 2012
Posts: 52
Hi,

I'm trying to use hibernate 4 with spring 3.1 but i've this issue and i can't find any solution:
nCreationException: Error creating bean with name 'sessionFactory'
defined in ServletContext resource [/WEB-INF/hibernate-context.xml]:
Invocation of init method failed;
nested exception is java.lang.NoClassDefFoundError:
Could not initialize class org.springframework.orm.hibernate4.LocalSessionFactoryBuilder

Maybe i miss a jar but i don't know which one or a conflict between two jars.
For now, i use this jar:

c3p0-0.9.1.2.jar
javax.transaction_1.1.0.jar
dom4j-1.6.1.jar
commons-logging-1.1.1.jar
jstl-1-2.2.jar
log4j-1.2.17.jar

hibernate-core-4.1.7
hibernate-validator-4.1.0
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate-commons-annotations-4.0.1.Final.jar

spring-orm-3.1.2
spring-asm-3.1.2
spring-beans-3.1.2
spring-context-3.1.2
spring-core-3.1.2
spring-expression-3.1.2
spring-tx-3.1.2
spring-web-3.1.2
spring-webmvc-3.1.2
spring-aop-3.1.2
spring-jms-3.1.2
spring-transaction-3.1.2

Here is my hibernate-context.xml


and my creationUser-context.xml




Anyone has a solution to make it work?
Emanuel Kadziela
Ranch Hand

Joined: Mar 24, 2005
Posts: 186
What about the MySQL jdbc driver jar? I don't see it in your list.
fabian verbeek
Ranch Hand

Joined: Oct 20, 2012
Posts: 52
My jar mysql-connector-java-5.1.22 is include directly in my tomcat 7.0 server

I've already use hibernate and mysql with success but without spring :-s

thanks for your help
Emanuel Kadziela
Ranch Hand

Joined: Mar 24, 2005
Posts: 186
is that the whole stack trace, or is there more?
fabian verbeek
Ranch Hand

Joined: Oct 20, 2012
Posts: 52
here is the complete trace

[code=xml GRAVE: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory'
defined in ServletContext resource [/WEB-INF/hibernate-context.xml]: Invocation of init method failed;
nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.orm
.hibernate4.LocalSessionFactoryBuilder
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.
initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.
getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.
preInstantiateSingletons(DefaultListableBeanFactory.java:591)
at org.springframework.context.support.AbstractApplicationContext
.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
at org.springframework.web.servlet.FrameworkServlet.
configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:857)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.springframework
.orm.hibernate4.LocalSessionFactoryBuilder
at org.springframework.orm.hibernate4.LocalSessionFactoryBean
.afterPropertiesSet(LocalSessionFactoryBean.java:277)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.
initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 33 more
10 déc. 2012 20:17:30 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Exception lors de l'allocation pour la servlet CreationUser
java.lang.NoClassDefFoundError
: Could not initialize class org.springframework.orm.hibernate4.LocalSessionFactoryBuilder
at org.springframework.orm.hibernate4
.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:277)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.
invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.
initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.
getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.
preInstantiateSingletons(DefaultListableBeanFactory.java:591)
at org.springframework.context.support.AbstractApplicationContext.
finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
at org.springframework.web.servlet.FrameworkServlet.
configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:857)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680 ][/code]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

"Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.springframework
.orm.hibernate4.LocalSessionFactoryBuilder "

There you go. The stack trace always tells you your problem. And I could have sworn you asked this in another thread.

You are missing the class from your classpath, so you are missing the spring-orm jar file from your classpath.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
fabian verbeek
Ranch Hand

Joined: Oct 20, 2012
Posts: 52
Hi,

For information, i use Eclipse and under my directory lib i've spring-orm-3.1.2.jar
If i click right on my project and go to java build path, in tab libraries my jar is present.

How can i do? Is it possible a conflict between 2 jar

Thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

fabian verbeek wrote:Hi,

For information, i use Eclipse and under my directory lib i've spring-orm-3.1.2.jar
If i click right on my project and go to java build path, in tab libraries my jar is present.

How can i do? Is it possible a conflict between 2 jar

Thanks


Yes, that is possible. Or different versions, where your Spring jar is say 3.0.5 and you added the Spring orm jar 3.1.2

Mark
fabian verbeek
Ranch Hand

Joined: Oct 20, 2012
Posts: 52
I join the jar that's include in my project and as you can see th eversion is 3.1.2

thanks for your patience and your help


[Thumbnail for Capture d’écran 2012-12-20 à 18.32.34.png]

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Are you using Maven? If so, can you post your pom file?

Thanks

Mark
fabian verbeek
Ranch Hand

Joined: Oct 20, 2012
Posts: 52
I don't use maven it'll be the next step, for now i put my jars in the lib directory
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

One thing might be the version of Spring and support for Hibernate 4.

I found this from doing a Google search. Maybe it can help.

http://blog.springsource.org/2012/04/06/migrating-to-spring-3-1-and-hibernate-4-1/

Mark
fabian verbeek
Ranch Hand

Joined: Oct 20, 2012
Posts: 52
I found the solution!!!
i added jboss-logging-3.1.2.GA.jar

in fact, at the start of my trace i had a message: java.lang.NoClassDefFoundError: org/jboss/logging/BasicLogger

thanks and see you soon
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

fabian verbeek wrote:I found the solution!!!
i added jboss-logging-3.1.2.GA.jar

in fact, at the start of my trace i had a message: java.lang.NoClassDefFoundError: org/jboss/logging/BasicLogger

thanks and see you soon


Cool.

This is why I like using Maven. Because I put in a dependency like Hibernate, and any dependency it needs comes down too. Because, secondary dependencies are impossible to track down manually.

Mark
fabian verbeek
Ranch Hand

Joined: Oct 20, 2012
Posts: 52
Do you know an easy tuto to transform a web project to maven project?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hibernate 4 and spring 3.1.2 issue with LocalSessionFactoryBuilder
 
Similar Threads
Need help in understanding JMockit Usage
Simple JPA application on TOMEE
usage of "this"
The "this" keyword and the constructor.
JSF 2.0 MyConverter.getAsObject(...) how to get a handle on the backing bean