PropertyAccessException: exception setting property with CGLIB

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.

5 Responses to PropertyAccessException: exception setting property with CGLIB

  1. Camilo Gonzalez says:

    Yes, it seems that mapping a primitive type to a nullable column generates that error.

    Thanks for your help.

  2. Anonymous says:

    I believe it’s any time there is an exception inside a set or get method on your object.

  3. Anthony says:

    Your information is very helpful.

    Thanks,
    Anthony

  4. Mudasir says:

    the most of the problem was with that of primitive types. actually hibernate expects only objects to be displayed

  5. Benoît de Chateauvieux says:

    Many thanks, my problem was of this type.
    Now it’s working fine.
    Thanks

    Benoît

%d bloggers like this: