为了账号安全,请及时绑定邮箱和手机立即绑定

hibernate异常

Exception in thread "main" java.lang.ExceptionInInitializerError
 at com.zjx.entity.Test1.add(Test1.java:32)
 at com.zjx.entity.Test1.main(Test1.java:17)
Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
 at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:185)
 at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
 at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:399)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857)
 at com.zjx.util.HibernateUtil.<clinit>(HibernateUtil.java:21)
 ... 2 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:138)
 at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:188)
 at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:403)
 at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:520)
 at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:148)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
 at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
 ... 6 more
Caused by: java.lang.reflect.InvocationTargetException
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
 at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:135)
 ... 15 more
Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for student in class com.zjx.entity.Grade
 at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:310)
 at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:304)
 at org.hibernate.mapping.Property.getGetter(Property.java:323)
 at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:411)
 at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:200)
 at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:80)
 ... 20 more

这是什么问题啊

正在回答

3 回答

配置文件写错了

0 回复 有任何疑惑可以回复我~

public class Grade implements Serializable {

 private int gid;
 private String gname;
 private String gdesc;
 
 //在一方定义多方的集合
 private Set<Student> students = new HashSet<Student>();

 public Grade(){
  
 }
 public Grade(int gid, String gname, String gdesc, Set<Student> students) {
  super();
  this.gid = gid;
  this.gname = gname;
  this.gdesc = gdesc;
  this.students = students;
 }

 public Grade(String gname, String gdesc) {
  super();
  this.gname = gname;
  this.gdesc = gdesc;
 }
 public int getGid() {
  return gid;
 }

 public void setGid(int gid) {
  this.gid = gid;
 }

 public String getGname() {
  return gname;
 }

 public void setGname(String gname) {
  this.gname = gname;
 }

 public String getGdesc() {
  return gdesc;
 }

 public void setGdesc(String gdesc) {
  this.gdesc = gdesc;
 }

 public Set<Student> getStudents() {
  return students;
 }

 public void setStudents(Set<Student> students) {
  this.students = students;
 }
 
 
 
}

public class Student implements Serializable {

 private int sid;
 private String sname;
 private String sex;
 
 //在多方定义一方的引用
 private Grade grade;
 
 public Grade getGrade() {
  return grade;
 }

 public void setGrade(Grade grade) {
  this.grade = grade;
 }

 public Student() {
  
 }
 
 public Student(String sname, String sex) {
 
  this.sname = sname;
  this.sex = sex;
 }

 public int getSid() {
  return sid;
 }
 public void setSid(int sid) {
  this.sid = sid;
 }
 public String getSname() {
  return sname;
 }
 public void setSname(String sname) {
  this.sname = sname;
 }
 public String getSex() {
  return sex;
 }
 public void setSex(String sex) {
  this.sex = sex;
 }
 
 
 
}

0 回复 有任何疑惑可以回复我~

在你没有贴源码的前提下暂时判断是某个entity实体缺少无参构造方法。

0 回复 有任何疑惑可以回复我~
#1

离锁忧 提问者

我都有添加无参的构造方法啊
2015-10-15 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Hibernate初探之一对多映射
  • 参与学习       42171    人
  • 解答问题       295    个

Hibernate中一对多关联映射配置,以及cascade和inverse属性作用

进入课程

hibernate异常

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信