-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem with null for primitive type
PostPosted: Fri Jan 12, 2007 12:46 pm 
Senior
Senior

Joined: Mon Jul 24, 2006 8:43 am
Posts: 160
Hi,
I have primitive java long type field on my POJO. If there is a record in the database table for this POJO and the corresponding column value for the long type is of value null, the exception:

org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter.....

in cases when the entity is queried.

I read the hibernate spec, it says one way around this is to use a Java wrapper object and make the field a Long instead of a long.

Now, I want to keep it a primitive. I would have thought if this field is optional, it should be allowed to null, even if it is a primitive.

My understanding is that optional=true is the default but I mark the field explictly to be optional using:

@Basic(optional=true)

I still get the same exception.

Any ideas how I can get around this?

I wish to use primitives who's setters will be ignored should the value be null in the database.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 12, 2007 8:24 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
As soon as you manage to compile
Code:
long size = null;

I'll make the change :-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 12, 2007 8:26 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
BTW you can achieve what you want by using @Type and writing your own user type that does the magic

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 05, 2007 6:55 am 
Newbie

Joined: Mon Feb 05, 2007 6:46 am
Posts: 2
Location: Brussel
Hi,

I am facing the same problem. Why would you create your own UserType?
Can't you just work with the Long wrapper class. That class should be able to handle NULL values, doesn't it?

Kind regards,

_________________
Sam


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.