This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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.
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.
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.
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 ]
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.