File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Primitive vs Wrapper type in Maping file

 
Xavier George
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While creating the mapping file, either we use Java Primitive or Java Wrapper. When I used tool to generate the mapping file for me, it used combination of both primitive and wrapper type. But, which one is good to used from performance point of view and best practice. Could anyone suggest me rule when to use primitive and when to use wrapper. I will definitely go for simple primitive type over wrapper.

Thanks for your time reading my post.

I got the following andswer from Hibernate forum.

hibernate core doesn't care it uses the same hibernate type for both wrapper and primitive.

the code generator does care though since it is the only way that it can see wether you want primitive or non-primitive.

so technically it only matters if you use codegeneration.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64186
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Xavier Gr", you have previously been warned on one or more occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it prior to your next post.

Your display name must be a first and a last name separated by a space character, and must not be obviously fictitious. Initials or abbreviations for a last name are not acceptable.

Be aware that accounts with invalid display names are disabled.

bear
JavaRanch Sheriff
[ July 31, 2006: Message edited by: Bear Bibeault ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually in the mapping file when you use type="string" you are not actually defining the property type in the Class , or the field type in the database. It is a Hibernate type that Hibernate uses to map a Java type to a vendor database type. For instance the "long" maps with the long primitive or the Long wrapper object of Java and the correlating field types in the database that you defined in your database dialect.

Mark
 
Xavier George
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actaully, this debate came to my mind, when Hibenate Tools generated the mapping file and POJO and it uses the combination of primitive vs. wrapper in POJO. And, moreover the tools is assiging primitive/wrapper type in POJO based on the data-type and size. But, most of the place I observed that wrapper can be easily deal with primitive. And, I dont want to pay extra for using wrapper, I am happy with primitive.

Anyway, thanks for your reply.
 
Scott Johnson
Ranch Hand
Posts: 518
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A wrapper is useful for storing nulls. If you use a primitive you can define a specific value (like 0 for an integer) to be a placeholder for null, but to me it's more intuitive to use a wrapper class instead.
[ July 31, 2006: Message edited by: Scott Johnson ]
 
Ghulam Rashid
Ranch Hand
Posts: 278
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats true, wrapper is useful on some situation and cant be avoided. But, I will use wrapper only when it is needed or I will simply go for primitive. Creating a wrapper object using new keyword is expensive and it wont be realize for low traffic site.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic