gpt4 book ai didi

Hibernate 抛出 org.hibernate.persister.entity.SingleTableEntityPersister

转载 作者:行者123 更新时间:2023-12-04 15:59:54 25 4
gpt4 key购买 nike

我正在将 JBoss AS 7 与 H2 数据库一起使用。
我有一个独立的应用程序,它尝试像这样连接到这个数据库。

我的配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="Test">
<property name="hibernate.connection.driver_class">org.h2.Driver</property>
<property name="hibernate.connection.url">jdbc:h2:mem:test</property>
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
<mapping class="Kunde" resource="Kunde.hbm.xml"/>
<mapping class="Mitarbeiter" resource="Mitarbeiter.hbm.xml"/>
</session-factory>
</hibernate-configuration>

我的映射文件是:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Oct 26, 2012 7:34:15 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="Kunde" table="KUNDE">
<id name="id" type="long">
<column name="ID" />
<generator class="assigned" />
</id>
<property name="vorname" type="java.lang.String">
<column name="VORNAME" />
</property>
<property name="nachname" type="java.lang.String">
<column name="NACHNAME" />
</property>
<property name="firma" type="java.lang.String">
<column name="FIRMA" />
</property>
</class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Oct 26, 2012 7:34:15 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="Mitarbeiter" table="MITARBEITER">
<id name="id" type="long">
<column name="ID" />
<generator class="assigned" />
</id>
<property name="vorname" type="java.lang.String">
<column name="VORNAME" />
</property>
<property name="nachname" type="java.lang.String">
<column name="NACHNAME" />
</property>
</class>
</hibernate-mapping>

我的实体类:
public class Kunde {
long id;
String vorname;
String nachname;
String firma;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getVorname() {
return vorname;
}

public void setVorname(String vorname) {
this.vorname = vorname;
}

public String getNachname() {
return nachname;
}

public void setNachname(String nachname) {
this.nachname = nachname;
}

public String getFirma() {
return firma;
}

public void setFirma(String firma) {
this.firma = firma;
}
}

(另一个看起来相似)。

我的测试代码:
public static void main(String[] args) {
try {
// This step will read hibernate.cfg.xml and prepare hibernate for
// use
Configuration configuration = new Configuration();
configuration.configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
.applySettings(configuration.getProperties())
.buildServiceRegistry();
SessionFactory sessionFactory = configuration
.buildSessionFactory(serviceRegistry);

Session session = sessionFactory.openSession();

// Create new instance of Kinde and set values in it by reading them
// from form object
System.out.println("Inserting Record");
Kunde kunde = new Kunde();
kunde.setId(1);
kunde.setVorname("A");
kunde.setNachname("N");
kunde.setFirma("Privat");
session.save(kunde);
System.out.println("Done");

// Actual insertion will happen at this step
session.flush();
session.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}

异常(exception):
Okt 26, 2012 7:56:45 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Okt 26, 2012 7:56:45 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.0.1.Final}
Okt 26, 2012 7:56:45 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Okt 26, 2012 7:56:45 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Okt 26, 2012 7:56:45 AM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Okt 26, 2012 7:56:45 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Okt 26, 2012 7:56:45 AM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: Kunde.hbm.xml
Okt 26, 2012 7:56:45 AM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: Mitarbeiter.hbm.xml
Okt 26, 2012 7:56:45 AM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: Test
Okt 26, 2012 7:56:45 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Okt 26, 2012 7:56:45 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
Okt 26, 2012 7:56:45 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: false
Okt 26, 2012 7:56:45 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [org.h2.Driver] at URL [jdbc:h2:mem:test]
Okt 26, 2012 7:56:45 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {}
Okt 26, 2012 7:56:46 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
Okt 26, 2012 7:56:46 AM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
Okt 26, 2012 7:56:46 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Okt 26, 2012 7:56:46 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister

任何的想法?

更新:

愚蠢的我 :)

我打印了整个堆栈跟踪,这表明我的类路径不完整:
Caused by: java.lang.ClassNotFoundException: javassist.util.proxy.MethodFilter
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 23 more

我添加了 javaassist JAR,现在工作正常。

对不起。

最佳答案

可能你需要使用 javassistjar 文件;我使用了 javassist-3.10.0.GA.jar 并且这个错误消失了

关于Hibernate 抛出 org.hibernate.persister.entity.SingleTableEntityPersister,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13081608/

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