Java:Web应用程序中的hibernate - 无法实例化默认的tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

时间:2012-03-22 15:42:08

标签: java hibernate jsp pojo

我在Web应用程序中遇到了Hibernate的奇怪问题,虽然我没有在测试独立应用程序中遇到它。

面-config.xml中

    <managed-bean>
        <managed-bean-name>businessUserData</managed-bean-name>
        <managed-bean-class>org.beans.BusinessUserDataHibernate</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
        <managed-property>
            <property-name>daoUserData</property-name>
            <value>#{daoUserData}</value>
        </managed-property> 
    </managed-bean>     
    <managed-bean>
        <managed-bean-name>daoUserData</managed-bean-name>
        <managed-bean-class>org.data.source.DAOuserDataHibernate</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>

DAOuserDataHibernate.getUserData() - 我在BusinessUserDataHibernate类中用作服务类

     public UserData getUserData(String userName){
        sessionFactory = new Configuration().configure().buildSessionFactory();     
        UserData userData=null;
        try{
            session = sessionFactory.openSession();
            tx = session.beginTransaction();
            userData = (UserData)session.get(UserData.class, userName);
            tx.commit();            
                    session.close();
            return userData;
        }
        catch(HibernateException hEx){ return null; }                           
    }

的hibernate.cfg.xml

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/mySQLdb</property>
        <property name="connection.username">...</property>
        <property name="connection.password">...</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and create the database schema on startup -->
        <property name="hbm2ddl.auto">update</property>

        <mapping resource="UserData.hbm.xml"/>

    </session-factory>

</hibernate-configuration>

UserData.hbm.xml

<hibernate-mapping package="org.hibernate">

    <class name="UserData" table="UserData">
        <id name="userId" column="id" type="string"/>
        <property name="xmlData" type="clob"/>
    </class>

</hibernate-mapping>

我导入的罐子

http://i.stack.imgur.com/BiCMk.jpg

当我从独立的测试应用程序运行应用程序时它工作正常(hibernate根据我调用的DAO方法选择数据或写入数据库)。当我将它部署到WAR并在 Glasfish3 服务器上运行时,它会转储

堆栈跟踪

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.data.source.DAOuserHibernate.getAllUsers(DAOuserHibernate.java:61)
    at org.spring.beans.BusinessUserHibernate.getAllUsers(BusinessUserHibernate.java:33)

我尝试了不同的方式,也支持Spring,但最终我得到了这个例外。它似乎与构建 sessionFactory 有某种关联。你能帮我解决这个问题。

提前谢谢你 马尔钦

2 个答案:

答案 0 :(得分:0)

我遇到了同样的问题但是在添加javassist.jar后它已经解决了。我使用maven进行依赖管理。我这样添加了

<dependency>
    <groupId>javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.12.1.GA</version>
</dependency>

请检查尝试更改您的javssist版本

答案 1 :(得分:0)

这可能不是您的情况,但是当使用Java 11而不是预期的Java 8时,Hibernate会抛出此异常