[url]http://cagataycivici.wordpress.com/2006/01/03/propertyaccessexception_exception_setting_property_with/[/url]
PropertyAccessException: exception setting property with CGLIB
I haven’t been writing about common hibernate exceptions for a while until yesterday; I got this error
我一直以来没有关于hibernbate 的异常信息的文字,直到昨天我遇到了一个错误如下:
PropertyAccessException: exception setting property with cglib
There are two reasons I’ve observed.
我分析有两个原因:
Incompatible types between the hibernate mapping and the model being mapped
在映射文件和被映射的模型之间有不匹配的类型信息
For example you have a Set of objects but in the mapping file this relation is mapped as a list. When hibernate tries to set the values in the db to the model, the exception will be thrown because mapping is incompatible. Solution is to make the model and the mapping compatible.
Mapping a primitive type to a nullable column
映射了一个私有类型的属性到一个null列中
This one is also a common mistake, the reason is again a compatibility issue, primitives cannot be null and when hibernate observes the value in the mapped column is null then it tries to set a null value to a primitive which is invalid.In order to overcome this error, you can either assign a default value to the primitive value in the code like 0 or change the primitive to a wrapper which means use Integer instead of int.
PropertyAccessException: exception setting property with CGLIB
I haven’t been writing about common hibernate exceptions for a while until yesterday; I got this error
我一直以来没有关于hibernbate 的异常信息的文字,直到昨天我遇到了一个错误如下:
PropertyAccessException: exception setting property with cglib
There are two reasons I’ve observed.
我分析有两个原因:
Incompatible types between the hibernate mapping and the model being mapped
在映射文件和被映射的模型之间有不匹配的类型信息
For example you have a Set of objects but in the mapping file this relation is mapped as a list. When hibernate tries to set the values in the db to the model, the exception will be thrown because mapping is incompatible. Solution is to make the model and the mapping compatible.
Mapping a primitive type to a nullable column
映射了一个私有类型的属性到一个null列中
This one is also a common mistake, the reason is again a compatibility issue, primitives cannot be null and when hibernate observes the value in the mapped column is null then it tries to set a null value to a primitive which is invalid.In order to overcome this error, you can either assign a default value to the primitive value in the code like 0 or change the primitive to a wrapper which means use Integer instead of int.
本文解析了在使用Hibernate过程中遇到的PropertyAccessException异常,主要原因是映射文件与模型之间的类型不匹配及原始类型映射到可为空的列中。文章提供了具体的解决办法。
4926

被折叠的 条评论
为什么被折叠?



