Java自学者论坛

 找回密码
 立即注册

手机号码,快捷登录

恭喜Java自学者论坛(https://www.javazxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,会员资料板块,购买链接:点击进入购买VIP会员

JAVA高级面试进阶训练营视频教程

Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程Go语言视频零基础入门到精通Java架构师3期(课件+源码)
Java开发全终端实战租房项目视频教程SpringBoot2.X入门到高级使用教程大数据培训第六期全套视频教程深度学习(CNN RNN GAN)算法原理Java亿级流量电商系统视频教程
互联网架构师视频教程年薪50万Spark2.0从入门到精通年薪50万!人工智能学习路线教程年薪50万大数据入门到精通学习路线年薪50万机器学习入门到精通教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程MySQL入门到精通教程
查看: 8061|回复: 0

Hibernate常见异常总结

[复制链接]
  • TA的每日心情
    奋斗
    2024-4-6 11:05
  • 签到天数: 748 天

    [LV.9]以坛为家II

    2034

    主题

    2092

    帖子

    70万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    705612
    发表于 2021-4-6 14:49:46 | 显示全部楼层 |阅读模式

    系统配置

    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

    哎...今天够累的,签到来了1...
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|小黑屋|Java自学者论坛 ( 声明:本站文章及资料整理自互联网,用于Java自学者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2024-5-17 17:44 , Processed in 0.063903 second(s), 29 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表