aspose file tools*
The moose likes Object Relational Mapping and the fly likes Primitive vs Wrapper type in Maping file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Primitive vs Wrapper type in Maping file" Watch "Primitive vs Wrapper type in Maping file" New topic
Author

Primitive vs Wrapper type in Maping file

Xavier George
Ranch Hand

Joined: Jul 29, 2005
Posts: 39
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

Joined: Jan 10, 2002
Posts: 61648
    
  67

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Xavier George
Ranch Hand

Joined: Jul 29, 2005
Posts: 39
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

Joined: Aug 24, 2005
Posts: 518
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

Joined: Jan 14, 2002
Posts: 278
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.
 
Don't get me started about those stupid light bulbs.
 
subject: Primitive vs Wrapper type in Maping file