1.org.hibernate.NonUniqueObjectException
主键冲突。查看是否插入相同的数据,或者主键的生成策略没有选对(没带自增长的),而导致。
http://blog.csdn.net/qq_33054511/article/details/54630938,有主键的生成策略讲解。
2. java.lang.ClassCastException
类型转换异常,查看是否倒错包导致类型转换错误或者是你自己的类型转换错误。
3. org.hibernate.InstantiationException: No default constructor for entity: com.hibernate.entity.grade
java bean缺少无参的构造方法。
4.Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.hibernate.entity.student column: gid (should be mapped with insert="false" update="false")
重复映射的问题,在多对一中<many-to-one></many-to-one>中指定column与原有的配置的column重复,如下所示:
<property name="gid" type="int">
<column name="gid" />
</property>
<many-to-one name="gr" class="com.hibernate.entity.grade" column="gid">
</many-to-one>
5.Exception in thread "main" java.lang.ExceptionInInitializerError
at com.hibernate.entity.test.add1(test.java:35)
at com.hibernate.entity.test.main(test.java:10)
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:385)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1790)
at hibernate_test.HibernateUtil.<clinit>(HibernateUtil.java:18)
... 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:341)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:507)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:146)
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:423)
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:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:135)
... 15 more
Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for grd in class com.hibernate.entity.student
at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:316)
at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:310)
at org.hibernate.mapping.Property.getGetter(Property.java:321)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:444)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:200)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:82)
查看多对一配置中name属性与实体类多方中的一方是否匹配,如下name="grd"与实体类中private grade gr;不同导致以上错误
<many-to-one name="grd" class="com.hibernate.entity.grade" column="gid"></many-to-one>
public class student {
private int sid;
private String sname;
private String sex;
private int gid;//所在的班级
private grade gr;//在多方定义一方
public student() {
super();
}
//getter,setter省略
}