-->
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.  [ 7 posts ] 
Author Message
 Post subject: Long vs long
PostPosted: Thu Jul 28, 2005 7:06 pm 
Beginner
Beginner

Joined: Thu Jul 28, 2005 6:40 pm
Posts: 29
Hi;

The book "Hibernate in Action" uses Long for the PK. However, I have used long and it works fine. Is there an advantage to using Long?

thanks - dave


Top
 Profile  
 
 Post subject: Re: Long vs long
PostPosted: Thu Jul 28, 2005 7:13 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
david@windward.net wrote:
Hi;

The book "Hibernate in Action" uses Long for the PK. However, I have used long and it works fine. Is there an advantage to using Long?

thanks - dave


Long allows you to have NULL values.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 7:31 pm 
Beginner
Beginner

Joined: Thu Jul 28, 2005 6:40 pm
Posts: 29
Yes, but it is used for PKs and AFAIK you cannot have a NULL PK

??? - thanks - dave


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 8:04 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
david@windward.net wrote:
Yes, but it is used for PKs and AFAIK you cannot have a NULL PK

??? - thanks - dave


You're right, BUT you only talk about objects which are already in the database (persistent objects) and have a primary key. Objects can also be transient - when they are created (Object o = new Object()). In this case they usually have no primary key (except for the situation the key is assigned manually and not by the database) and they are marked being transient using the XML attribute "unsaved-value". This can be NULL in case of a Long and must be another value for long, since a long cannot be NULL.

I think there is also information about this (transient and persistent state) in the documentation and HiA book.

Best regards
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 8:26 pm 
Beginner
Beginner

Joined: Thu Jul 28, 2005 6:40 pm
Posts: 29
OOOOOOOOOOOOOH

That makes a lot of sense. (That's why I ask questions like this - a lot of time there is a very good reason to do it that way.)

thanks - dave


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 8:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Just a suggestion. The above posting was helpful so mark his post as helpful. Its good feedback and rewards posters in a small way.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 12:29 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
sven wrote:

database (persistent objects) and have a primary key. Objects can also be transient - when they are created (Object o = new Object()). In this


I dont think this is the main reason since long can just have unsaved as 0, so it works similarly, especially if you have a native key which starts above 0. If you are putting your ID as the key of a Map, or passing it to methods that take Object as an input, then the long type will need to be constantly wrapped and unwrapped, but the Long one is already there. Its not a ton of overhead, but for performance nuts, reducing the number of instances created matters.

Chris


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