Hibernate


Hibernate.hbm.xml

1、should be mapped with insert="false" update="false":存在重復映射的字段;

2、Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]:

配置文件與實體文件映射錯誤,多了字段或少了字段或少些了getter 方法;

3、org.hibernate.LazyInitializationException: could not initialize proxy - no Session:映射關系中加上 lazy="false";

4、org.hibernate.ObjectNotFoundException: No row with the given identifier exists:根據外鍵id查詢不到映射表的相應數據;

5、Could not determine type for: String, for columns: [org.hibernate.mapping.Column(XXX)]:type指的是*.hbm.xml配置文件中的類型,string要小寫;

6、nested exception is org.hibernate.ObjectNotFoundException: No row with the given identifier exists:映射表中數據的主鍵id不匹配;

7、org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of XXX:配置文件與實體類字段類型不一致;

8、org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1:級聯新增,打印出來的sql語句顯示主表為insert,從表為update  可以將配置文件中自增id設置 unsaved-value="0";

9、ConstraintViolationException: Could not execute JDBC batch update:兩個表建立了外鍵約束,刪除約束后操作成功;

10、 nested exception is org.springframework.beans.NotWritablePropertyException:

11、org.springframework.beans.factory.BeanCreationException:Spring中的“asm-2.2.3.jar”和Hibernate中的“asm.jar”包沖突。解決辦法是移除Spring2.0 AOP Libraries中的“asm-2.2.3.jar”即可

12、org.springframework.beans.MethodInvocationException: 在classes目錄有一個以前的類,但現在的類的路徑已經發生了變化,發生變化的類全部封裝在 jar 里面,但class loader 是優先裝載 classes 目錄下的類,所以存在裝載時發生“NoClassDefFoundError”錯誤!只要把classes下的class文件刪除即可。

13、com.sun.faces.mgbean.ManagedBeanCreationException:數據問題

14、a different object with the same identifier value was already associated with the session:getHibernateTemplate().merge(object);http://chenying.blog.51cto.com/614874/134702

15、not-found="ignore" 忽略ObjectNotFound異常;

轉載地址:http://blog.csdn.net/hardwin/article/details/4329652

我們項目里面配了很多many-to-one的關聯,后台在查詢數據時已經作了健全性判斷,但還是經常拋出對象找不到異常:org.hibernate.ObjectNotFoundException: No row with the given identifier exists

因為系統給用戶使用過程中庫表的數據會常發生變化,最常見的是人員變化,原先引用的User 在庫表沒了,hibernate 多對一關聯,多的這端引用的一的那端,如此引用值在一的那端找不到數據,默認就會拋出異常;而后台判斷控制不了此問題。解決辦法就是在many-to- one的這端加上屬性:not-found=ignore

hibernate many-to-one的屬性not-found,用來指定引用的外鍵不存在時如何處理:

它有兩個取值,exception(默認)拋出異常,ignore 忽略。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM