Hi,
I cannot seem to find an easy way to get Hibernate auto-default values on nullable fields that are mapped as primitive data types, such as "boolean" or "long" when Hibernate reads data from database into an Entity object.
For example, if boolean field defined as NUMBER(1) in database has a NULL value, I'd like it to be read into its corresponding "boolean" mapped field on the Entity class as "false" value.
Instead, I'm getting "org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter" error.
I can certainly define my fields with the Wrapper classes, such as Boolean and Long and then code logic in my getter method to return "false" and 0, respectively. But this seems like lot of mechanical work for something that I was hoping an ORM tool to have an automatic support for?
For example, TopLink has setNullValue(..) method (on oracle.toplink.mappings.foundation.AbstractDirectMapping) that can be used on the mapping definition to define the default value to be used in NULL cases. Does Hibernate have any similar kind of support?
Thanks, Dmitriy.
|