0

spring+hibernate problem

asked 2010-03-20 09:45:24 +0800

yuanbohan gravatar image yuanbohan
258 2 7

I don't know why the zk framework does not support it. I just an not understand. Do I have to use the way zk supports them , but not the spring + hibernate themselves?

When I use the junit to test the configuration, well, it works. but when I use the test.zul to test the configuration, then the problem apperas!! My God..!! ssh framework does support this kind of configuration. But the zk framework just doesn't let me go ...

The wrong information is the following:

Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deriSessionFactory' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org.hibernate.cfg.Configuration
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org.hibernate.cfg.Configuration
Caused by: java.lang.NoClassDefFoundError: org.hibernate.cfg.Configuration
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.class$(LocalSessionFactoryBean.java:158)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.<init>(LocalSessionFactoryBean.java:158)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:85)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:757)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:722)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:386)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:285)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:189)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:630)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:556)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:491)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2010-3-20 14:34:08 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deriSessionFactory' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org.hibernate.cfg.Configuration
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org.hibernate.cfg.Configuration
Caused by: java.lang.NoClassDefFoundError: org.hibernate.cfg.Configuration
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.class$(LocalSessionFactoryBean.java:158)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.<init>(LocalSessionFactoryBean.java:158)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:85)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:757)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:722)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:386)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:285)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:189)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:630)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:556)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:491)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2010-3-20 14:34:08 org.apache.catalina.core.StandardContext start
严重: Error listenerStart

*********************the web.xml file is:*********************

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>SPRING_HIBERNATE</display-name>

<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.xml</param-value>
</context-param>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

<listener>
<description>
Used to cleanup when a session is destroyed</description>
<display-name>ZK Session cleaner</display-name>
<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
</listener>



<servlet>
<description>
The ZK loader for ZUML pages</description>
<servlet-name>zkLoader</servlet-name>
<servlet-class>
org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
<init-param>
<param-name>update-uri</param-name>
<param-value>/zkau</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<description>
The asynchronous update engine for ZK</description>
<servlet-name>auEngine</servlet-name>
<servlet-class>
org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zul</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>auEngine</servlet-name>
<url-pattern>/zkau/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>index.zul</welcome-file>
</welcome-file-list>
</web-app>


*********************the applicationContext.xml file is like this:*********************

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans >

<bean id="deriSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>hibernate.cfg.xml</value>
</property>
</bean>

<bean id="sensorDao" class="ie.deri.lion2.backend.daoImpl.SensorDAOImpl" singleton="true">
<property name="sessionFactory">
<ref bean="deriSessionFactory" />
</property>
</bean>

<bean id="sensorService" class="ie.deri.lion2.backend.serviceImpl.SensorServiceImpl">
<property name="sensorDAO">
<ref bean="sensorDao"/>
</property>
</bean>

</beans>

*********************the hibernate.cfg.xml file is like this:*********************

<!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.connection.url"> jdbc:mysql://localhost/deri</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">deri</property>

<property name="hibernate.connection.maxActive">100</property>
<property name="hibernate.connection.maxIdle">30</property>
<property name="hibernate.connection.maxWait">1000</property>

<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>

<mapping resource="ie/deri/lion2/backend/bean/Sensor.hbm.xml"/>
<mapping resource="ie/deri/lion2/backend/bean/DeriBuilding.hbm.xml"/>
</session-factory>
</hibernate-configuration>


*********************The junit to test the configuration is like this:*********************
//ZKDevTest.java

package ie.deri.lion2.junit;

import ie.deri.lion2.backend.service.SensorService;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import junit.framework.TestCase;

public class ZKDevTest extends TestCase {
public void testApplicationContextLoad(){
BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
SensorService service = (SensorService)factory.getBean("sensorService");
System.out.println(service.getClass().getSimpleName());
}
}
// the output is:
2010-03-20 14:41:59,421 INFO ClassPathXmlApplicationContext M - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@b8bef7: display name [org.springframework.context.support.ClassPathXmlApplicationContext@b8bef7]; startup date [Sat Mar 20 14:41:59 GMT 2010]; root of context hierarchy
2010-03-20 14:41:59,531 INFO XmlBeanDefinitionReader M - Loading XML bean definitions from class path resource [applicationContext.xml]
2010-03-20 14:41:59,781 INFO ClassPathXmlApplicationContext M - Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@b8bef7]: org.springframework.beans.factory.support.DefaultListableBeanFactory@11ca803
2010-03-20 14:41:59,828 INFO DefaultListableBeanFactory M - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@11ca803: defining beans [deriSessionFactory,sensorDao,sensorService]; root of factory hierarchy
2010-03-20 14:42:00,375 INFO LocalSessionFactoryBean M - Building new Hibernate SessionFactory
SensorServiceImpl

I want to know if I have to use the way zk framework supports spring+hibernate, I can not use another way to integrate with spring + hibernate. And who can tell me the exact way to do the job? I have read the small-talks about the zk+spring+hibernate, Is there another way to do the same work?

HELP ME, MY GOD ....!!!!

delete flag offensive retag edit

4 Replies

Sort by » oldest newest

answered 2010-03-21 08:57:32 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

    I don't know why the zk framework does not support it.

Well, it does, but the error that you're getting has absolutely zero to do with ZK.

   I want to know if I have to use the way zk framework supports spring+hibernate

I don't really understand what you mean by "the way zk framework supports spring+hibernate." If you're asking if you have to use ZK Spring, no. There is no requirement to use that in order to use Spring + Hibernate in your projects. Mine don't have it and they integrate ZK + Spring + Hibernate fine.

The error you're getting has everything to do with your classpath. You should tell us more information like your IDE, your app server + version, and project layout with the jars in them, and how you're deploying the application to the server (stand alone war or ear + wars). I use Eclipse with its typical Dynamic Web Project layout and have the jars in my WEB-INF/lib. I deploy to Tomcat, so there are no ear's involved. Each web app has its own copy of the jar's. Have you placed the Hibernate jar's in the app server's classpath, by chance? This error is bad verbage for "I have found the class in a different classloader but you don't have access to it via that classloader."

link publish delete flag offensive edit

answered 2010-03-22 05:05:48 +0800

yuanbohan gravatar image yuanbohan
258 2 7

Thanks for your help. I use Tomcat 6.0, MySql 5.0, and jee eclipse tools. I will try to make it as the way you told me. Thanks a million. It has made me crazy already.^_^

link publish delete flag offensive edit

answered 2011-01-06 20:19:13 +0800

jmontoya gravatar image jmontoya
6 1

Hello Do you have a sample to kz + spring and hibernate.

Thanks

link publish delete flag offensive edit

answered 2011-01-07 09:38:15 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

Here's a little demo app I did awhile back and updated slightly the other day: http://clarktrips.intltwins.org/zkmvcdemo0.2.zip
The Hibernate based DAO definition is commented out in the Spring context. And there might be a missing jar or two. It compiles, but I didn't try to run it...

And if you get totally bored or frustrated, you can waste a little time by visiting http://clarktrips.intltwins.org and see me and my brothers. I'm on the left.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-03-20 09:45:24 +0800

Seen: 1,058 times

Last updated: Jan 07 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More