-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to automatically default values on nullable primitives?
PostPosted: Wed May 07, 2014 3:40 pm 
Newbie

Joined: Thu Feb 27, 2014 2:53 pm
Posts: 2
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.