使用Hibernate框架在开发中可能遇到的几个异常(更......)

1、如果session中出现相同oid的两个对象,

 1 NonUniqueObjectException:A different object with same identifier value w...... 

2、托管对象的oid如果在数据表中不存在,

 1 StaleStateException:Batch update returned row count from update[0]...... 

建议:通过持久化对象来直接进行修改操作

3、load方法查询不到数据时,会产生异常

 1 ObjectNotFoundException 

4、持久化对象关联了一个瞬时对象----

1 org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: cn.it8090.domain.

解决:级联缓存,设置cascade

5、配置错误,mapping-->class---resource

Caused by: org.hibernate.boot.MappingNotFoundException: Mapping (RESOURCE) not found : cn.it8090.onetomany.Customer : origin(cn.it8090.onetomany.Customer)

6、实体类的属性中使用了 HashSet<T> hashSet = new HashSet<>(); ArrayList<> list = new ArrayList<>();  等类似这样没有父类引用指向子类对象的集合,会保如下的错。

{java.lang.ExceptionInInitializerError
Caused by: org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: cn.it8090.manytomany.Student.teachers}

解决:使用父类引用指向子类对象即可。(没有找到具体的原因)

7、运用hibernate框架进行命名检索的时候

{ava.lang.ExceptionInInitializerError
Caused by: java.lang.IllegalArgumentException: node to traverse cannot be null!}

解决:检查hql语句是否正确。

8、使用getCurrentSession()获取的与线程绑定的session对象,在事务关闭时,session对象也会close。简单说。不需要手动close。

{org.hibernate.SessionException: Session was already closed}

未完待续。。。。2017-11-23    21:23:17

 

转载于:https://www.cnblogs.com/11749penger/p/7887064.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值