gpt4 book ai didi

java - 无法获取 org.hibernate.persister.entity.SingleTableEntityPersister 错误的构造函数

转载 作者:数据小太阳 更新时间:2023-10-29 02:44:26 25 4
gpt4 key购买 nike

我不是 hibernate 的常客。我正在尝试创建多对一映射,但出现错误 (subj)。我一直在寻找类声明中的错误,还有 getter(最后一个错误),但一切似乎都是正确的。有人在我的代码中看到任何错误吗?因为我无法弄清楚。

Adres.java

package beans;

public class Adres {

int id;
String adresas;
String adname;

public Adres() {
}

public int getId() {
return id;
}

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

public String getAdresas() {
return adresas;
}

public void setAdresas(String adresas) {
this.adresas = adresas;
}

public String getAdname() {
return adname;
}

public void setAdname(String adname) {
this.adname = adname;
}
}

Men.java

package beans;

public class Men {

int id;
String name;

Adres adres;

public Men() {
}

public int getId() {
return id;
}

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

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Adres getAdd() {
return adres;
}

public void setAdd(Adres adres) {
this.adres = adres;
}
}

hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/db2</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.connection.password">pass</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="hbm/Men.hbm.xml"/>
<mapping resource="hbm/Adres.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Men.hbm.xml

<hibernate-mapping>
<class name="beans.Men" table="MEN">
<id column="id" name="id" type="int">
<generator class="native"/>
</id>
<property column="name" name="name" type="string"/>
<many-to-one class="beans.Adres" column="adres" name="adres" not-null="true"/>
</class>
</hibernate-mapping>

Adres.bbm.xml

<hibernate-mapping>
<class name="beans.Adres" table="ADRES">
<id name="id" type="int" column="id">
<generator class="native"/>
</id>
<property name="adresas" column="adresas" type="string"/>
<property name="adname" column="adname" type="string"/>
</class>
</hibernate-mapping>

Main.java

private static SessionFactory factory;

public static void main(String[] args) {
try {
factory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Failed to create sessionFactory object." + ex);
throw new ExceptionInInitializerError(ex);
}
}

Error log

Initial SessionFactory creation failed.org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
Exception in thread "main" java.lang.ExceptionInInitializerError
at main.HibernateUtil.<clinit>(HibernateUtil.java:15)
at main.Main.main(Main.java:17)
Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:123)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:77)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:346)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at main.HibernateUtil.<clinit>(HibernateUtil.java:12)
... 1 more
Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:91)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:116)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:388)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:508)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:124)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:96)
... 7 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:88)
... 16 more
Caused by: org.hibernate.PropertyNotFoundException: Could not locate getter method for property [beans.Men#adres]
at org.hibernate.internal.util.ReflectHelper.findGetterMethod(ReflectHelper.java:400)
at org.hibernate.property.access.internal.PropertyAccessBasicImpl.<init>(PropertyAccessBasicImpl.java:41)
at org.hibernate.property.access.internal.PropertyAccessStrategyBasicImpl.buildPropertyAccess(PropertyAccessStrategyBasicImpl.java:27)
at org.hibernate.mapping.Property.getGetter(Property.java:299)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:270)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:145)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:63)
... 21 more

最佳答案

您应该更改 Men 类中 adres 属性的 getter 和 setter

public Adres getAdd() {
return adres;
}

public void setAdd(Adres adres) {
this.adres = adres;
}

public Adres getAdres() {
return adres;
}

public void setAdres(Adres adres) {
this.adres = adres;
}

我建议给一个有意义的变量名和相关的getters,setters!

关于java - 无法获取 org.hibernate.persister.entity.SingleTableEntityPersister 错误的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34022746/

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