
hibernate
文章平均质量分 54
Lena-Yang
The best way to predict the future is to invent it. if you look for it, you won’t find it.
展开
-
hibernate分组与聚合查询(原生sql和使用case when then else end的hql)
需求:根据某些字段进行分组查询,并使用聚合函数sum()有条件的进行统计 一、用hibernate使用原生sql进行查询 // 服务器调配情况统计查询类 IdcStatisticSpecpublic class IdcStatisticSpec extends AbstQueryStringSpec { /** 机房ID */ private Integer c原创 2009-07-15 14:00:00 · 11213 阅读 · 3 评论 -
hibernate many-to-one关联,多的一端关联一的一端的外键对应数据被删了,如何避免抛出ObjectNotFoundException
我们项目里面配了很多many-to-one的关联,后台在查询数据时已经作了健全性判断,但还是经常抛出对象找不到异常:org.hibernate.ObjectNotFoundException: No row with the given identifier exists 因为系统给用户使用过程中库表的数据会常发生变化,最常见的是人员变化,原先引用的User 在库表没了,hibernate原创 2009-07-07 23:45:00 · 5194 阅读 · 1 评论 -
hibernate annotation方式配置实体关联关系,解决关联外键数据不存在时抛出异常的问题
使用hibernate 注解配置实体类的关联关系,在many-to-one,one-to-one关联中,一边引用自另一边的属性,如果属性值为某某的数据在数据库不存在了,hibernate默认会抛出异常。解决此问题,加上如下注解就可以了:@NotFound(action=NotFoundAction.IGNORE),意思是找不到引用的外键数据时忽略,NotFound默认是exception原创 2009-07-08 12:41:00 · 7921 阅读 · 1 评论