-->
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.  [ 6 posts ] 
Author Message
 Post subject: Null value was assigned to a property of primitive type sett
PostPosted: Tue Jan 13, 2004 8:05 am 
Newbie

Joined: Wed Jan 07, 2004 8:48 am
Posts: 11
Hi,

I'm working on an existing database, generating the bindings and classes with Middlegen.
I'm working on customers and their orders. From a customer object, I call
getCustomerOrders() and get a Set of Orders. There are orders which have an int field set to NULL, which is the cause of my error message:
Code:
net.sf.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of mscustdb.hibernate.CustomerOrder.OrderCode


One possible solution would be to set this field to a special integer value (like 0 ) that we may be sure was not used as an order code. I'd prefer to not touch the data however.

Also I suspect I'll have more occurences of this problem, so I would like to find a better, general solution to put in my code.

Should I generate bindings and classes only with Integer types and no int? Is that possible?

Thanks in advance for your help!

Raph


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 8:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
If you have null values in your DB you should of course use Integers for your properties


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 8:29 am 
Newbie

Joined: Wed Jan 07, 2004 8:48 am
Posts: 11
gloeglm wrote:
If you have null values in your DB you should of course use Integers for your properties


Ok.

Is there a way to configure middlegen to specify Integer rather than int?

Thanks.

Raph


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 9:00 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Check the forum, I think it was answered some times ago.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 9:13 am 
Newbie

Joined: Wed Jan 07, 2004 8:48 am
Posts: 11
emmanuel wrote:
Check the forum, I think it was answered some times ago.


Thanks for the help!

It seems the solution is to get the cvs version for now:

http://forum.hibernate.org/viewtopic.php?t=926856&highlight=middlegen&sid=df49253b2c9f0e1c3ba6425a665a208e

From the link above (by David):
Quote:

The next version of Hibernate Middlegen plugin has the ability to use a specialised JavaTypeMapper which can be applied to avoid it generating native types for nullable fields. Its all in CVS (Middlegens') if you want to play. The code includes a custom JavaTypeMapper which can be plugged in that has this feature.


Raph


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 11:39 am 
Newbie

Joined: Wed Jan 07, 2004 8:48 am
Posts: 11
I've found an even faster solution, and that fits my needs.

I have decided to replace all int mapping by a Integer mapping.
All I had to do it edit the file src/PROJECTNAME-prefs.properties and replace the mappings in it. This file is loaded by hbm2java .

The JavaTypeMapper seems to be much more flexible, but I don't really need it and discovered this alternative solution before getting to the point of using it.

Raph


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