-->
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.  [ 3 posts ] 
Author Message
 Post subject: Can Hibernate ignore nulls for primitives?
PostPosted: Thu Feb 24, 2005 1:07 pm 
Beginner
Beginner

Joined: Wed Feb 09, 2005 3:27 pm
Posts: 29
I'm mapping a table to a class that uses primitives in the getter/setter methods, e.g. public long getQuantity() and public void setQuantity(long). The class doesn't use fields in the traditional sense, e.g. there's no private long quantity. Instead the class is backed by another storage mechanism (think of it like a hashmap that accepts primitives). Changing the database or changing the class are not valid options. The semantics of the class is such that the absence of a key in the 'hashmap' means the value is null. Is it possible to instruct Hibernate to skip processing of these attributes if the database column is null? In other words, if the column QUANTITY is null do not call setQuantity(long)? If not, is there another approach that will achive the same result?

Thanks,

-Kaare


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 3:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Use a custom PropertyAccessor, this should work I think.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 26, 2005 12:55 am 
Beginner
Beginner

Joined: Wed Feb 09, 2005 3:27 pm
Posts: 29
Yes, you're right this works.

Just to summarize the solution: the custom setter will receive the instance of the class that has the property plus the value from the database, and will make the decision of whether to set the value and what method (or field) to use.

Thanks, Michael!

-Kaare


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

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.