-->
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.  [ 4 posts ] 
Author Message
 Post subject: Updating/Creating -- Objects vs. their unique ids
PostPosted: Mon Jan 26, 2004 1:20 pm 
Beginner
Beginner

Joined: Wed Dec 03, 2003 2:43 pm
Posts: 22
Hi,

Say, for example, I have a State object. This State object has the following properties:

id - the unique id
shortName - the short name such as "WY"
longName - the long name such as "Wyoming".

Now say I have a Person object, which using a many to many association has a method getStatesVisited() that returns a Collection of State objects.

If I want to create a Person from an html form that gives me these State ids, wouldn't I have to load all the State objects from the database before I could create the Person?

Certainly, in this caseI could keep all the State objects in memory in a Singleton, for example, to make them easier to access but I was wondering if there were another hibernate pattern that made it easier to create/update objects when just given the Collection objects' ids rather than the objects themselves.

Thanks,
Gabe


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2004 1:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You have to load the objects all by id. The simplest solution would be to just use a second-level cache for the State Objects. This would spare you the database hits and would be very easy to implement, because the state data will most likely never change. A read-only cache would be sufficient.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 3:36 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You can also proxy state, so loading them, won't load it until your really access non id properties. Thus only linking person to state won't load state

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 6:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Ah yes, I allways forget about that one - thats really a cool feature.


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