-->
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.  [ 6 posts ] 
Author Message
 Post subject: Ono to one mapping
PostPosted: Wed May 19, 2010 12:25 pm 
Newbie

Joined: Fri Apr 02, 2010 8:40 am
Posts: 9
Hi guys,

Let say I have 1 to 1 mapping between two objects Body and Head

is there a more efficient way when setting Body to the head than load Head fist and vice versa ?

so :
1. Load Body
2. Load new Head
3. Set new Head to the Body
4. store Body
-----what I want-----
I know PK of Head
so
1. Load Body
2. Somehow set PK for new Head to the Body
3. Store Body

Cheers


Top
 Profile  
 
 Post subject: Re: Ono to one mapping
PostPosted: Wed May 19, 2010 5:50 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Assuming that you not have disabled proxies for your classes, you can use Session.load() to load the Head. This will not hit the database. It will only create a proxy for Head with the given ID value.


Top
 Profile  
 
 Post subject: Re: Ono to one mapping
PostPosted: Thu May 20, 2010 12:32 pm 
Newbie

Joined: Fri Apr 02, 2010 8:40 am
Posts: 9
Well,

does it depends on lazy settings as well ? Or are you saying that when I do Session.load() never hits the database ? What if the object with specified ID does not exists ?

Cheers


Top
 Profile  
 
 Post subject: Re: Ono to one mapping
PostPosted: Thu May 20, 2010 12:34 pm 
Newbie

Joined: Fri Apr 02, 2010 8:40 am
Posts: 9
right I see ... should use Session.get if want to be sure it exists ... thanks


Top
 Profile  
 
 Post subject: Re: Ono to one mapping
PostPosted: Thu May 20, 2010 2:22 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
does it depends on lazy settings as well ? Or are you saying that when I do Session.load() never hits the database ? What if the object with specified ID does not exists ?


lazy=true means that proxies are enabled, lazy=false means that proxies are disabled. If proxies are disabled I think Session.load() will hit the database and throw an exception if it doesn't exists (Session.get() returns null instead). If proxies are enabled Session.load() will return a proxy without checking the database. If it doesn't exists you may get an error later on depending on what you do.

Using Session.get() will be like the 4-step sequence in the original post.

Using Session.load() will be like the 3-step sequence in the original post.


Last edited by nordborg on Fri May 21, 2010 1:21 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Ono to one mapping
PostPosted: Fri May 21, 2010 11:52 am 
Newbie

Joined: Fri Apr 02, 2010 8:40 am
Posts: 9
thx


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