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?