-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate Best Practices - Primitive or Non-Primitive Types
PostPosted: Fri May 02, 2008 4:25 pm 
Beginner
Beginner

Joined: Wed Mar 05, 2008 10:32 am
Posts: 48
When defining my columns, is it better to use Primitive or Non-Primitive types?

I have been using Non-Primitive but noticed that eclipse's autogeneration for Boolean values is a "get" function not a "is" function as a boolean var would be.

This got me thinking if i'm doing it properly. I'm using annotations as well.


Top
 Profile  
 
 Post subject: suggestion
PostPosted: Sun May 04, 2008 4:24 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
From a logic pov, non-primitives like Long and Boolean may have a null value (in case they are not used as entity IDs), while primitives cannot.

As far as bean naming conventions are concerned, Eclipse is using a valid convention for booleans, so it shouldn't really matter.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 05, 2008 11:05 am 
Beginner
Beginner

Joined: Wed Mar 05, 2008 10:32 am
Posts: 48
So in essance, what your saying is that it is better to use non primitive since your values are being translated to sql columns that could potentially have null values.

It seemed that when i converted my booleans to Booleans, it did not yell at me to change my getters to getXXX rather than isXXX and thus working fine with current code. Will i ever see a problem with this?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 05, 2008 2:52 pm 
Newbie

Joined: Thu Dec 06, 2007 2:07 am
Posts: 3
Quote:
So in essance, what your saying is that it is better to use non primitive since your values are being translated to sql columns that could potentially have null values.


It's simply a matter of Boolean fields being first-class objects, which allows them to contain null values, rather than being restricted to the true/false value of a primitive boolean (which defaults to false). It's really more a matter of your domain dictating which type is appropriate for your use case than a matter of "correctness" per se.

Quote:
It seemed that when i converted my booleans to Booleans, it did not yell at me to change my getters to getXXX rather than isXXX and thus working fine with current code. Will i ever see a problem with this?


As sagimann indicated, the accessor methods that are auto-generated by Eclipse simply follow convention depending on the field type. Primitive boolean fields are referenced by isXXX and setXXX, while first-class objects (such as Boolean) are referenced by the getXXX and setXXX convention. You didn't get "yelled at" because you could, conceivably, name them whatever you want - but in the name of "purity", I would personally recommend that you follow standard convention for whatever type you choose.

Again, it is really your domain that determines whether or not your choice will cause any problems down the line.

Hope that helps.


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