系統配置
1.沒有查找到src目錄下的hibernate.cfg.xml
Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xmlnot found
映射配置
2.在系統配置文件cfg.xml文件中寫的映射文件名不存在
Exception in thread "main" org.hibernate.MappingNotFoundException: resource: cn/itcast/h3/user/UserModel.hbm.xml not found
3.配置文件中的映射屬性名與模型中的屬性名不統一
Caused by: org.hibernate.PropertyNotFoundException: field [name] not found on cn.itcast.h3.user.UserModel
4.配置文件中的數據庫列名名與數據庫表中的字段名名不統一
Caused by: java.sql.BatchUpdateException: Unknown column 'user' in 'field list'
操作增刪改
5.在進行保存前,如果對象OID沒有設置值,並且生成策略為assigned
Exception in thread "main" org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): cn.itcast.h3.user.UserModel
6.當操作保存一個數據時,如果OID對應的值存在
Exception in thread "main" org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
Caused by: java.sql.BatchUpdateException: Duplicate entry '5' for key 1
7.執行增刪改語句發生錯誤,具體操作具體分析
Exception in thread "main" org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
8.進行刪改語句未找到影響的數據,拋出該異常,OID不存在
Exception in thread "main" org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
9.Hibernate在試圖操作一個對象時,檢測出該對象是TO對象,不具有OID,而執行非save相關的操作
Exception in thread "main" org.hibernate.TransientObjectException: The given object has a null identifier: cn.itcast.h3.cache.UserModel
10.一級緩存中加載兩個不同的對象具有相同的OID數據
Exception in thread "main" org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [cn.itcast.h3.cache.UserModel#15]
操作查詢
11.使用load方法讀取數據時,如果對應的OID不存在數據
Exception in thread "main" org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [cn.itcast.h3.api.UserModel#100]
12.QBC查詢時,直接使用關聯對象名.屬性名作為查詢條件
Exception in thread "main" org.hibernate.QueryException: could not resolve property: teacher.teacherName of: cn.itcast.h3.relation.vo.StudentModel
13.對HQL進行參數設置時,索引位置錯誤
Exception in thread "main" org.hibernate.QueryParameterException: Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 2
14.查詢結果不唯一,使用uniqueResult方法得到超過一條數據
Exception in thread "main" org.hibernate.NonUniqueResultException: query did not return a unique result: 5
其他
15.在Hibernate操作對象過程中試圖修改對象的OID
Exception in thread "main" org.hibernate.HibernateException: identifier of an instance ofcn.itcast.h3.cache.UserModel was altered from 3 to null
16.操作數據時,一個數據關聯了瞬時對象,拋出異常
Exception in thread "main" org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: cn.itcast.h3.one2many.StudentModel
17.當Session關閉后,試圖加載對象中延遲加載數據
Exception in thread "main" org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: cn.itcast.h3.relation.vo.TeacherModel. students, no session or session was closed