PropertyAccessException: exception setting property with CGLIB
January 3, 2006 5 Comments
I haven’t been writing about common hibernate exceptions for a while until yesterday; I got this error
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
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.