-->
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: hbm2java - ObjectRequired for nullable fields
PostPosted: Tue Jan 06, 2004 12:55 pm 
Newbie

Joined: Tue Jan 06, 2004 12:34 pm
Posts: 1
Hi,
I'm currently investigating using Middlegen and hbm2java to generate hbm files and java code based on an existing schema. I am using version 2.0.2 of Hibernate extensions built October 2003

I have encountered problems with the definition of native types for nullable columns by hbm2java. For example if I have an int column which is not part of any constraint and is nullable I (and I think Hibernate) would expect this column to be mapped to java.lang.Integer in the generated java class - however I get an int.

Looking at ClassMapping::initWith() below you can see that for properties 'nullable' is evaluated but not used in the call to getFieldType() and is subsequently defaulted to false. Is this a simple bug or am I missing something?

Code:
         
         // handle in a different way id and properties...
         // ids may be generated and may need to be of object type in order to support
         // the unsaved-value "null" value.
         // Properties may be nullable (ids may not)
         if (property == id)  {...         
         }
         else {
            String notnull = property.getAttributeValue("not-null");
            // if not-null property is missing lets see if it has been
            // defined at column level
            if(notnull == null) {
               Element column = property.getChild("column");
               if(column != null)
                  notnull = column.getAttributeValue("not-null");
            }
           
boolean nullable = ( notnull == null || notnull.equals("false") );
            boolean key = property.getName().startsWith("key-"); //a composite id property
            ClassName t = getFieldType(type);
            addImport(t);
            Field stdField =new Field(name, t, nullable && !key, key, false, metaForProperty);
            fields.add(stdField );


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 4:52 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
use "java.lang.Integer" instead of just "int" as the type.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 10:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
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.


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.