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: Passing related object via id
PostPosted: Wed Jul 19, 2006 10:55 am 
Newbie

Joined: Sun May 28, 2006 7:42 pm
Posts: 19
Location: Italy
Hi, is there any way to save an object passing its parent id guid and not the istance ?

Example:

Account a = new Account(new Guid(), prop1, prop2. prop3....)

a.Office= (here i pass an instace of persisted class Office).

May i pass a Guid identificator instead of an instance.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 5:09 pm 
Newbie

Joined: Sun May 28, 2006 7:42 pm
Posts: 19
Location: Italy
Up.

Can anyone answer me!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 5:36 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Assuming Office is lazy, you can do a.Office = session.Load(typeof(Office), officeId);

in this case session.Load will not go to the database, it will only create a proxy for Office.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 25, 2006 11:16 am 
Newbie

Joined: Sun May 28, 2006 7:42 pm
Posts: 19
Location: Italy
ok, thanks. So, any way, i need to call database to get persistent class.

I'm try to work disconnected from DB. What's your advise to do this.
I think i need to load all Offices entity at first connection to DB and than when i create a new account i can associate it.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 25, 2006 5:34 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
If an object is lazy and you use load you'll just get a proxy to the object with no actual database hit. The database will only be hit if you touch one of the proxy's properties (it's Id excepted, of course).

The proxy is in effect recognized as an actual object, so if you set the Account.Office property to the proxy then when you save or update the Account object it will have a reference to the object that the proxy represents.

To do this you need to know the id of the office you want to get a proxy for, of course...

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 30, 2006 10:34 am 
Newbie

Joined: Sun May 28, 2006 7:42 pm
Posts: 19
Location: Italy
merge_s.rottem wrote:
If an object is lazy and you use load you'll just get a proxy to the object with no actual database hit. The database will only be hit if you touch one of the proxy's properties (it's Id excepted, of course).

The proxy is in effect recognized as an actual object, so if you set the Account.Office property to the proxy then when you save or update the Account object it will have a reference to the object that the proxy represents.

To do this you need to know the id of the office you want to get a proxy for, of course...

Symon.


Great i didn't know this. Your answer was very helpful for me.

Thanks


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.