-->
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.  [ 2 posts ] 
Author Message
 Post subject: primitive type VS object of the key field
PostPosted: Sat Feb 07, 2004 6:52 am 
Beginner
Beginner

Joined: Thu Dec 04, 2003 3:47 am
Posts: 31
Location: Hong Kong
When some of the fields in the object is nullable, it should not be in primitive type but in object type, like Long instead of long.

I generate a dataobject with key in long type, and being "assigned", as the following

<id
name="thekey"
type="long"
column="ID"
>
<generator class="assigned" />
</id>

I use hbm2java to generate the corresponding java class. The generated class is as the following

/** identifier field */
private Long thekey;

I wonder why it generats Long instead of long (since the primary key is not nullable). Also, i find that when the key is "identity" instead of "assigned", it will then generate long. Can anyone help to explain why hbm2java has such behavouir? Any reasoning behind? what if I change to long manually?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 07, 2004 11:43 am 
Senior
Senior

Joined: Sun Jan 04, 2004 2:46 pm
Posts: 147
It's todo with the unsaved value that hibernate uses to determine whether an object is a brand new object or an existing object that has been changed.

http://www.hibernate.org/hib_docs/reference/html_single/#or-mapping-s1-4

I don't know much about hbm2java but I would speculate changing this to a value such as 0 or -1 or "any" or "none" would cause a long to be generated. Try it and see what happens.

You should read this section

http://www.hibernate.org/hib_docs/reference/html_single/#manipulating-data-s8

to make sure you understand the consequences of changing this setting.

Cheers.

Myk.


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