Hibernate+中遇到的一些错误

来源:互联网 发布:手机淘宝怎么退款退货 编辑:程序博客网 时间:2024/05/17 17:39


1、org.hibernate.LazyInitializationException: could not initialize proxy - no Session

这个异常遇到时是在关联关系中采取的惰性加载,将加载属性改为lazy="false"即可,如:

<many-to-one name="unit" class="net.hnspi.researchtrace.bean.Unit" lazy="false"><column name="Unitid" not-null="true" /></many-to-one>

2、ERROR org.hibernate.property.BasicPropertyAccessor:122 - expected type: java.util.HashSet, actual value: org.hibernate.collection.PersistentSet

这个问题的根源是在实体类中对于集合类型使用了具体的实现类型。如Set 使用的HashSet进行了代替,原因是Hibernate使用了其自己对于Set接口的实现org.hibernate.collection.PersistentSet,这样就会出现对HashSet的兼容错误了,然后就会出现这个错误。不过这个还是参考一个老外哥的帖子找出的答案,这里还是得感谢一下,原来的帖子出处是:http://grails.1312388.n4.nabble.com/property-BasicPropertyAccessor-expected-type-java-util-HashSet-actual-value-org-hibernate-collectiont-td1375479.html


3、对于hql的写法中"=:"不可有空格,如:

from Item i where i.del = false and i.itemId =:itemId


原创粉丝点击