gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 08:19:29 25 4
gpt4 key购买 nike

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

faces-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>

我导入的 jar

/image/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 以某种方式相关。您能帮我解决这件事吗?

提前谢谢您马尔辛

最佳答案

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

关于Java:Web 应用程序中的 hibernate - 无法实例化默认 tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9825701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com