Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
awamser
Post subject: Hibernate mapping to Integer  PostPosted: Jan 21, 2006 - 11:18 PM
Registered Member
Registered Member


Joined: Nov 29, 2005
Posts: 54

I'm guessing that I'm probably missing something simple, but I don't understand why the mapping tools maps to java.lang.Integer and not int. Then when using the setter method you have to add and extra step of creating a new integer. For example...

You have the following method in your abstract class...

public setAge(java.lang.Integer age) {
this.age = age
}


Create a new object and call the setter method would require creating a Integer.

setAge(new Integer(25))

if it was declared as int.

setAge(25)
 
 View user's profile Send private message  
Reply with quote Back to top
support-rkalla
Post subject:   PostPosted: Jan 22, 2006 - 11:22 PM
Registered Member
Registered Member


Joined: Jan 06, 2004
Posts: 23855

AFAIK this is preferred for Hibernate. Hibernate deals only in objects and when you map to native fields yourself, I believe (seems I read this somewhere, or looked at the code) that Hibernate is actually internally mapping from an Object to the native value to populate your POJO, so if you just leave it in Integer it saves you that conversion.


To ease your mind you can write a contrived micro-benchmark of creating millions of random Integers and see how much time it actually costs the VM. It's typically so insignifigant for 10s of thousands of instances that it would never be an issue in real life creating 10-20 or even 100 of them for a query.

_________________
Riyad
MyEclipse Support
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
snpe
Post subject:   PostPosted: Jan 23, 2006 - 03:41 AM
Quality Board
Quality Board


Joined: Jul 05, 2003
Posts: 548

hibernate use object internal (same type for Integer and int,for example), but there is more important reason for using obejct wrapper except primitive type - handling null value - you can't have null for primitive type
I don't use primitive type anywhere
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits