從休眠狀態獲取對象時遇到問題。堆棧跟蹤是:持久化實體中的InstantiationException
org.hibernate.InstantiationException: Could not instantiate entity: main.java.com.gwt.app.server.User
at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:114)
at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:123)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.instantiate(AbstractEntityTuplizer.java:603)
at org.hibernate.persister.entity.AbstractEntityPersister.instantiate(AbstractEntityPersister.java:3911)
at org.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:1422)
at org.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:1411)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1446)
at org.hibernate.loader.Loader.getRow(Loader.java:1355)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:611)
at org.hibernate.loader.Loader.doQuery(Loader.java:829)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.loadEntity(Loader.java:2037)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3293)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:1005)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:998)
at main.java.com.gwt.app.server.User.loadUser(User.java:50)
at main.java.com.gwt.app.server.GreetingServiceImpl.greetServer(GreetingServiceImpl.java:22)
at main.java.com.gwt.app.client.Main.main(Main.java:11)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:111)
... 25 more
Caused by: java.lang.NoClassDefFoundError: org.springframework.beans.FatalBeanException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:965)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:900)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:455)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
at main.java.com.gwt.app.server.User.<init>(User.java:33)
... 30 more
我User.hbm.xml文件是:
<hibernate-mapping package="main.java.com.gwt.app.server">
<class name="User" table="USR">
<id column="login" name="login" type="java.lang.String"/>
<property column="password" name="password" type="java.lang.String"/>
</class>
</hibernate-mapping>
和用戶等級:
package main.java.com.gwt.app.server;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
public class User {
private String login;
private String password;
private SessionFactory sesionFactory;
private Session sesion;
public void setSesionFactory(SessionFactory sesionFactory){
this.sesionFactory = sesionFactory;
this.sesion = this.sesionFactory.openSession();
}
public User(String user, String pass) {
ClassPathResource res = new ClassPathResource("resources/spring.xml");
XmlBeanFactory factory = new XmlBeanFactory(res);
this.sesionFactory = (SessionFactory)factory.getBean("sessionFactory");
this.sesion = this.sesionFactory.openSession();
this.login = user;
this.password = pass;
}
public User() {
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String loadUser(String log){
return ((User)sesion.get(User.class, log)).getLogin();
}
}
我在春天文件引用映射文件:
<property name="mappingResources">
<list>
<value>
User.hbm.xml
</value>
</list>
</property>
我使用的庫有:
hibernate3.jar
org.springframework.aop-3.1.0.M1.jar
org.springframework.asm-3.1.0.M1.jar
org.springframework.aspects-3.1.0.M1.jar
org.springframework.beans-3.1.0.M1.jar
org.springframework.context-3.1.0.M1.jar
org.springframework.context.support-3.1.0.M1.jar
org.springframework.core-3.1.0.M1.jar
org.springframework.expression-3.1.0.M1.jar
org.springframework.instrument-3.1.0.M1.jar
org.springframework.instrument.tomcat-3.1.0.M1.jar
org.springframework.jdbc-3.1.0.M1.jar
org.springframework.jms-3.1.0.M1.jar
org.springframework.orm-3.1.0.M1.jar
org.springframework.oxm-3.1.0.M1.jar
org.springframework.transaction-3.1.0.M1.jar
hibernate-validator-4.0.2.GA.jar
validation-api-1.0.0.GA.jar
所以,我不知道爲什麼是返回錯誤的原因。我需要幫助
謝謝!
和庫? – 2011-05-19 09:41:47
如果您查看異常堆棧跟蹤,您將看到一個由:NoClassDefFoundError引起的錯誤。這是應該解決的錯誤的原因。我懷疑Andreas_D是對的。 – SJuan76 2011-05-19 09:47:42
您的圖書館如何管理?並沒有進攻,但爲什麼你使用M1發佈的框架,你不熟悉? – abalogh 2011-05-19 10:05:10