-->
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: how to save object economically..
PostPosted: Fri Jan 16, 2004 4:10 pm 
Beginner
Beginner

Joined: Fri Jan 16, 2004 3:22 pm
Posts: 26
Hi, i'm using hibernate on a web application and not happy with the procedure i'm following to save a object, the app is about persons and their addresses :

- when creating a new address, from the user request i get the data. Also i get a string representing the id of the person owning that address.

- in order to save the address i create from the database a user object just to put it in address.setOwner( ) since its a required, not-null, property.

is there a better way to do it? just using the owner id i already have and without going to the database for the hole object.


regards!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 17, 2004 9:05 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is an ORM tool, not a RRM tool :)
Try to use the second level cache. you certainly get the user id from a previous hibernate request.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 17, 2004 11:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Just do:

Code:
Address a = new Address();
Person p = session.load(Person.class, id);
a.setOwner(p);


If Person is defined with proxy then load() won't hit the database - and neither will a.setOwner() as it just need to do p.getId() which also won't hit the database.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 17, 2004 2:03 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
max wrote:
If Person is defined with proxy then load() won't hit the database - and neither will a.setOwner() as it just need to do p.getId() which also won't hit the database.

Stupid of me, why don't I have think of that :)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2004 3:12 pm 
Beginner
Beginner

Joined: Fri Jan 16, 2004 3:22 pm
Posts: 26
ok, thanks.. so which object's lifetime is the cache associated with?
i mean, for instance, as long i as keep using the same sessionfactory i have access to the same cache?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2004 3:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
first-level-cache : Session
second-level-cache (ehchace, swarmcache ...) : SessionFactory


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.