這些Error是我平時遇到的,經過修改後都能解決問題,但每個Error的原因都不一定唯一,如果遇到符合的可以嘗試解決。希望可以給大家帶來方便,如果有什麼錯誤的地方還請大家指出。
1,Could not find a getter for id in class xx.xxx.Xxx:
原因:hbm.xml中沒有把類的id和數據庫表的id正確對應起來。
解決:檢查xxx.hbm.xml中的id配置,看哪裏與類或數據庫不符合。
-------------------------------------------------------------------------------------------------------
2,Exception in thread "main" org.hibernate.MappingException: Unknown entity:xx.xxx.Xxx
原因:hbm.xml文件的問題配置問題。不能把試實體類與數據庫表連接起來。
解決:仔細,再仔細檢查hbm.xml文件-------------------------------------------------------------------------------------------------------
3,object references an unsaved transient instance - save the transient instance before flushing: xx.xxx.Xxx
原因:hbm.xml中many-to-one配置時的錯誤
解決:在many-to -one標籤加入:cascade="save-update,persist"-------------------------------------------------------------------------------------------------------
4,is not writable or has an invalid setter method:
原因:SSH三大框架整合合時出的錯誤,應該是bean配置的屬性值與所在類的字段的變量名不相同引起的錯誤
例如:
<bean id="allAction" class="<span style="font-family:微軟雅黑;">xx</span>.<span style="font-family:微軟雅黑;">xxx</span>.AllAction" >
<property name="personDao">
<ref bean="personDao"/>
</property>
</bean>
在xx.xxx.Action類中,如果沒有變量名爲personDao的字段
private PersonDao personDao;
public PersonDao getPersonDao() {
return personDao;
}
public void setPersonDao(PersonDao personDao) {
this.personDao = personDao;
}
,就會報這個錯誤。
-------------------------------------------------------------------------------------------------------
5,org.springframework.orm.hibernate3.HibernateQueryException: person is not mapped:
原因:在網上查了資料,大概是hql語句中的類名沒有與現有的類名對應起來
例如:“from user”,而實體類是User.java這樣會產生上面的錯誤。
-------------------------------------------------------------------------------------------------------
6,java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
原因:很顯然是缺少了slf4j包
解決:1,添加一個slf4j-nop-1.6.0.jar包
2、把slf4j-api-1.5.2.jar 換成 slf4j-api-1.6.0.jar
參考:http://www.educity.cn/wenda/350738.html
-------------------------------------------------------------------------------------------------------
7,Connection cannot be null when 'hibernate.dialect' not set
原因:這個錯誤的原因有很多,可能是dialect配置錯了,有可能是Configuration方法中錯了。
解決:我遇到的原因是new Configuration()之後沒有調用configurate()方法-------------------------------------------------------------------------------------------------------
8,Exception in thread "main" 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:80)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:323)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:475)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:133)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:297)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385)
at org.jian.domain.Test.main(Test.java:25)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:107)
... 9 more
Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for teachers in class org.jian.domain.Teacher
at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:328)
at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:321)
at org.hibernate.mapping.Property.getGetter(Property.java:304)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:299)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:158)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:77)
... 14 more