Discussion:
[Middlegen-user] Issue: defined Primitive types versus Objects (CMP20 plugin)
Darren Hartford
2003-12-22 14:03:01 UTC
Permalink
Hey all,
This was a kicker to find. Have a database, it contains a Numeric field that is NULLable. Use CMP to connect to a J2EE application but get NullPointer exceptions during execution.

Instead of defining the Numeric as a java.lang.Integer object in the Entity Bean, it was defined as an 'int'.
public abstract int getMyNumberField();
public abstract void setMyNumberField(int myNumberField);

Is there a way to quickly fix this (outside of changing the generated source code), Then a gameplan to take care of it in the future? I know on the J2EE/CMP side you 99% always want Objects in the EntityBean, not sure on JDO side though. Thanks, I'm suprised no one else has run into this!

-D
Russell Simpkins
2003-12-22 14:20:04 UTC
Permalink
You can always edit the velocity template(s).

-----Original Message-----
From: middlegen-user-***@lists.sourceforge.net
[mailto:middlegen-user-***@lists.sourceforge.net] On Behalf Of Darren
Hartford
Sent: Monday, December 22, 2003 11:03 AM
To: middlegen-***@lists.sourceforge.net
Subject: [Middlegen-user] Issue: defined Primitive types versus Objects
(CMP20 plugin)

Hey all,
This was a kicker to find. Have a database, it contains a Numeric field
that is NULLable. Use CMP to connect to a J2EE application but get
NullPointer exceptions during execution.

Instead of defining the Numeric as a java.lang.Integer object in the
Entity Bean, it was defined as an 'int'.
public abstract int getMyNumberField();
public abstract void setMyNumberField(int myNumberField);

Is there a way to quickly fix this (outside of changing the generated
source code), Then a gameplan to take care of it in the future? I know
on the J2EE/CMP side you 99% always want Objects in the EntityBean, not
sure on JDO side though. Thanks, I'm suprised no one else has run into
this!

-D


-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for
IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys
admin.
Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=ick
Rod Macpherson
2003-12-22 22:06:00 UTC
Permalink
<cmp20 destination="${build.source}" blah blah blah...>
<fileproducer id="entity-cmp-20"
template="./template/entity-cmp-20.vm"/>
<jboss/>
<weblogic/>
</cmp20>

You can make a copy of entity-cmp-20.vm in your own folder (template in
this example) and edit it to your heart's content. Now you control the
output. As far as mapping types, however, there is a source for
middlegen.javax.Sql2Java.java that you can modify and rebuild middlgen.
Say you wanted Types.NUMERIC to translate as Double objects:

_preferredJavaTypeForSqlType.put(Types.NUMERIC,
"java.lang.Double");

Not sure if editing that source is recommended, however.

-----Original Message-----
From: Russell Simpkins [mailto:***@hotmail.com]
Sent: Monday, December 22, 2003 8:20 AM
To: middlegen-***@lists.sourceforge.net
Subject: RE: [Middlegen-user] Issue: defined Primitive types versus
Objects (CMP20 plugin)


You can always edit the velocity template(s).

-----Original Message-----
From: middlegen-user-***@lists.sourceforge.net
[mailto:middlegen-user-***@lists.sourceforge.net] On Behalf Of Darren
Hartford
Sent: Monday, December 22, 2003 11:03 AM
To: middlegen-***@lists.sourceforge.net
Subject: [Middlegen-user] Issue: defined Primitive types versus Objects
(CMP20 plugin)

Hey all,
This was a kicker to find. Have a database, it contains a Numeric field
that is NULLable. Use CMP to connect to a J2EE application but get
NullPointer exceptions during execution.

Instead of defining the Numeric as a java.lang.Integer object in the
Entity Bean, it was defined as an 'int'. public abstract int
getMyNumberField(); public abstract void setMyNumberField(int
myNumberField);

Is there a way to quickly fix this (outside of changing the generated
source code), Then a gameplan to take care of it in the future? I know
on the J2EE/CMP side you 99% always want Objects in the EntityBean, not
sure on JDO side though. Thanks, I'm suprised no one else has run into
this!

-D


-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for
IBM's Free Linux Tutorials. Learn everything from the bash shell to sys
admin. Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=ick
_______________________________________________
middlegen-user mailing list middlegen-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/middlegen-user


-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for
IBM's Free Linux Tutorials. Learn everything from the bash shell to sys
admin. Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=ick
_______________________________________________
middlegen-user mailing list middlegen-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/middlegen-user
Darren Hartford
2003-12-23 12:57:02 UTC
Permalink
Sent in a patch for CVS HEAD (12/23/2003).
http://sourceforge.net/tracker/index.php?func=detail&aid=865006&group_id=36044&atid=415992
Simply related to adding in a check to make the JAVA TYPE an Object for nullable fields - was originally only PK/FK. Hopefully someone will look at this and allow an option to have all JAVA TYPES be Objects for CMP20 for those that wish it.
-D

From: Russell Simpkins [mailto:***@hotmail.com]=20
Subject: RE: [Middlegen-user] Issue: defined Primitive types versus
Objects (CMP20 plugin)


You can always edit the velocity template(s).

-----Original Message-----
From: middlegen-user-***@lists.sourceforge.net
[mailto:middlegen-user-***@lists.sourceforge.net] On Behalf Of Darren
Hartford
Sent: Monday, December 22, 2003 11:03 AM
To: middlegen-***@lists.sourceforge.net
Subject: [Middlegen-user] Issue: defined Primitive types versus Objects
(CMP20 plugin)

Hey all,
This was a kicker to find. Have a database, it contains a Numeric field
that is NULLable. Use CMP to connect to a J2EE application but get
NullPointer exceptions during execution.

Instead of defining the Numeric as a java.lang.Integer object in the
Entity Bean, it was defined as an 'int'. public abstract int
getMyNumberField(); public abstract void setMyNumberField(int
myNumberField);

Is there a way to quickly fix this (outside of changing the generated
source code), Then a gameplan to take care of it in the future? I know
on the J2EE/CMP side you 99% always want Objects in the EntityBean, not
sure on JDO side though. Thanks, I'm suprised no one else has run into
this!

-D

Loading...