Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / May 2005

Tip: Looking for answers? Try searching our database.

hbm2java - use of "not-null" changes case of variable type

Thread view: 
O.B. - 21 May 2005 03:00 GMT
Using Hibernate Tools v 2.1.3, assume the following code is in a hbm.xml
file:

<property name="volume" type="short"/>

The hbm2java tool will produce:

/** nullable persistent field */
private Short volume;

However, if you add not-null to the property:

<property name="volume" type="short" not-null="true"/>

The hbm2java tool will produce:

/** persistent field */
private short volume;

Notice how "Short" changes to "short" (first letter is now lowercase).
Has anyone fixed this bug?
Christian Haselbach - 21 May 2005 09:26 GMT
> Notice how "Short" changes to "short" (first letter is now lowercase).
> Has anyone fixed this bug?

Why do you think this is a bug. I cannot find documentation about it but
my guess is that this is intended. The best way to avoid a null value is
to use a corresponding primitive. If you want the class, try to use the
type java.lang.Short (not just short).

Ciao Chriss
Murray - 21 May 2005 09:39 GMT
> Notice how "Short" changes to "short" (first letter is now lowercase).
> Has anyone fixed this bug?

It's not a bug, it's working exactly how it's supposed to.

If a field is declared as not-null, then it's possible to use a primitive
short to represent its value. However if it is nullable, this is not
possible and you need to use the wrapper object - Short - because primitives
can't be null.

You can of course use a Short on a not-null field if you want to, but
hbm2java defaults to a primitve short for simplicity and efficiency. If you
really need a Short wrapper object, maybe you could try using
type="java.lang.Short"
O.B. - 22 May 2005 05:37 GMT
>>Notice how "Short" changes to "short" (first letter is now lowercase).
>>Has anyone fixed this bug?
[quoted text clipped - 10 lines]
> really need a Short wrapper object, maybe you could try using
> type="java.lang.Short"

Ah, that makes sense.  So is it a best practice to force usage of
java.lang.Short?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.