2013-11-22 89 views
1

我開發與Hibernate和Spring的應用程序和APACH tomcate錯誤創建名稱爲bean的SessionFactory的「無法創建默認的tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

完整的堆棧跟蹤是:

GRAVE: Context initialization failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/HibernateSessionFactory.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1403) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450) 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:545) 
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871) 
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423) 
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:443) 
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:459) 
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:340) 
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:307) 
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127) 
at javax.servlet.GenericServlet.init(GenericServlet.java:160) 
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280) 
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193) 
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088) 
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176) 
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460) 
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) 
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) 
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) 
at java.util.concurrent.FutureTask.run(Unknown Source) 
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
at java.lang.Thread.run(Unknown Source) 
Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer] 
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:110) 
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:135) 
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56) 
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:323) 
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:433) 
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109) 
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55) 
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:231) 
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1313) 
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:855) 
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:774) 
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1460) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1400) 
... 28 more 

我的web.xml中:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> 
<description>Sample application</description> 
<display-name>RichFaces 4</display-name> 
<welcome-file-list> 
    <welcome-file>index.jsp</welcome-file> 
</welcome-file-list> 

<servlet> 
    <servlet-name>spring</servlet-name> 
    <servlet-class> 
     org.springframework.web.servlet.DispatcherServlet 
    </servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>spring</servlet-name> 
    <url-pattern>*.html</url-pattern> 
</servlet-mapping> 
</web-app> 

我爲spring-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:p="http://www.springframework.org/schema/p" 
xmlns:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 


http://www.springframework.org/schema/context 


http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

<context:component-scan 
    base-package="net.viralpatel.spring3.controller" /> 

<bean id="viewResolver" 
    class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
    <property name="viewClass" 
     value="org.springframework.web.servlet.view.JstlView" /> 
    <property name="prefix" value="/WEB-INF/site/" /> 
    <property name="suffix" value=".jsp" /> 
</bean> 

<import resource="DataSource.xml"/> 
<import resource="HibernateSessionFactory.xml"/> 
<bean id="hibernatetransactionManager" 

    class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 

    <property name="sessionFactory" ref="sessionFactory" /> 

</bean> 
</beans> 

我HibernateSessionFactory.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> 
<bean id="sessionFactory" 
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 

<property name="dataSource"> 
    <ref bean="dataSource"/> 
</property> 

<property name="hibernateProperties"> 
    <props> 
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> 
    <prop key="hibernate.show_sql">true</prop> 
    <prop key="hibernate.hbm2ddl.auto">update</prop> 
    </props> 
</property> 

<property name="mappingResources"> 
<list> 
     <value>Utilisateur.hbm.xml</value> 

</list> 
</property>  

</bean> 
</beans> 

我Utilisateur.hbm.xml

<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
<!-- Generated 7 nov. 2013 17:56:05 by Hibernate Tools 3.4.0.CR1 --> 
<hibernate-mapping package="model"> 
<class name="Utilisateur" table="UTILISATEUR"> 
    <id name="id" type="int"> 
     <column name="ID" /> 
     <generator class="assigned" /> 
    </id> 
    <property name="nom" type="java.lang.String"> 
     <column name="NOM" /> 
    </property> 
    <property name="prenom" type="java.lang.String"> 
     <column name="PRENOM" /> 
    </property> 
    <property name="code" type="java.lang.String"> 
     <column name="CODE" /> 
    </property> 
    <property name="sex" type="java.lang.String"> 
     <column name="SEX" /> 
    </property> 
    <property name="telephone" type="java.lang.String"> 
     <column name="TELEPHONE" /> 
    </property> 
    <property name="login" type="java.lang.String"> 
     <column name="LOGIN" /> 
    </property> 
    <property name="password" type="java.lang.String"> 
     <column name="PASSWORD" /> 
    </property> 

</class> 
</hibernate-mapping> 

我Utilisateur.java

package model; 

import java.util.Date; 
import java.util.List; 

public class Utilisateur { 
private Integer id; 
private String nom; 
private String prenom; 
private String code; 
private String sex; 
private String telephone; 
private String login; 
private String password; 
public Utilisateur() { 

} 
public Integer getId() { 
    return id; 
} 
public void setId(Integer id) { 
    this.id = id; 
} 
public String getSex() { 
    return sex; 
} 
public void setSex(String sex) { 
    this.sex = sex; 
} 
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 void setPrenom(String prenom) { 
    this.prenom = prenom; 
} 
public String getPrenom() { 
    return prenom; 
} 
public void setCode(String code) { 
    this.code = code; 
} 
public String getCode() { 
    return code; 
} 
public void setTelephone(String telephone) { 
    this.telephone = telephone; 
} 
public String getTelephone() { 
    return telephone; 
} 

/** 
* @param nom the nom to set 
*/ 
public void setNom(String nom) { 
    this.nom = nom; 
} 
/** 
* @return the nom 
*/ 
public String getNom() { 
    return nom; 
} 
} 

謝謝

+0

哪個彈簧/休眠版本。發佈您使用的庫。 –

回答

0

我有同樣的是起訴大約一個小時前和使用中的鏈接

http://jonathan.lalou.free.fr/?p=2026

問題是因爲使用Hibernate版本ASM罐子不兼容提到以下提示解決它。所以只要你改變它,問題就會解決。

確保將屬性標籤添加到依賴關係之外。還清理您的項目,以刪除目標文件夾中的所有內容然後乾淨地安裝你的maven來檢索所有兼容的罐子。

1

對比該文件Utilisateur.javaUtilisateur.hbm.xml

  • 檢查屬性名兩個文件是相同的
  • 包括一個默認的構造函數中Utilisateur.java
  • 你可能會錯過這個jar文件。 javassist.jar
當你遇到這個錯誤 無法實例默認的tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

。這是一個普通的信息。所以你必須看看導致錯誤的最後一行。這可能是解決方案。

相關問題