Hibernate映射导致的几个异常

异常1:not-null property references a null or transient value
解决方法:将“一对多”关系中的“一”方,not-null设置为false

异常2:org.hibernate.TransientObjectException: object references an unsaved transient instance
解决方法:cascade="save-update,persist"

异常3:org.hibernate.QueryException: could not resolve property
解决方法:"from Category category where category.userID = :userID"修改为"from Category category where userID = :userID"或者"from Category category where category.user.id = :userID"

异常4:could not initialize proxy - the owning Session was closed
解决方法:设置lazyfalse

另一种解决方案:

org.hibernate.PropertyValueException: not-null property references a null or transient value: com.bjcx.project.entity.task.Equipmenttable.ProjPortfolioID
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate

字面意思:一个不允许为Null的属性引用了一个为Null的或者无效的值。

原因:在***.hbm.xml中的

<property name="ProjPortfolioID" column="ProjPortfolioID"
    type="big_decimal" not-null="true" length="10" />

中,not-null="true",这说明属性ProjPortfolioID 不允许为空,而在ActionForm中未给他赋值,则就为空,所以就会报错!


posted on 2009-10-21 21:12 MichaelLee 阅读(380) 评论(0)  编辑  收藏 所属分类: Hibernater


只有注册用户登录后才能发表评论。


网站导航:
 
<2009年10月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

导航

统计

公告

====Michael Lee====
=Java Sofware Engineer=
=Work @ Beijing=
---再烦,也别忘微笑;再急,也要注意语气;再苦,也别忘坚持;再累,也要爱自己!---
---低调做人,你会一次比一次稳健;高调做事,你会一次比一次优秀---
---成功的时候不要忘记过去;失败的时候不要忘记还有未来---

常用链接

留言簿(2)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜