-->
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.  [ 2 posts ] 
Author Message
 Post subject: General Question Re: persisting relations
PostPosted: Mon Dec 06, 2004 8:18 pm 
Newbie

Joined: Mon Oct 11, 2004 1:30 pm
Posts: 15
Location: New York, NY
Take this code as an example:

/**
* A person has one or more contacts
*/
class Person {
String personId;
Set contacts;
}

/**
* A contact is related to one person.
*/
class Contact {
Person contactOf;
String emailAddress;
}

I'm relatively new with hibernate, but to the best of what I can determine, the relation must be modelled in the domain layer as such: with the Contact containing an instance of Person, as opposed to this:

class Contact {
String contactOfId;
String emailAddress;
}


This is perfectly okay except when, for example, I have a screen to allow the user to enter in a contact information, I would typically just pass the PK of the person and then associate the contact to the person using the PK.

In the hibernate scenario, it appears that I need to materialize a Person object, attach it to the Contact, and then call "session.save(contact)".

I guess I could craft an insert to do it explicitly, but it seems like overkill. Would much prefer it if hibernate could do the association by itself without the extra step of retrieving the Person object.

Thanks!

Ed.Q.B.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 7:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
If person was a lazy (or proxied) class then sess.load() would create the proxy [with the key] without hitting the database. This proxied domain object can then be added the the contact class to build the association.


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