-->
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.  [ 1 post ] 
Author Message
 Post subject: Setting fk directly in many-to-one.
PostPosted: Sun Jan 23, 2005 3:34 pm 
Newbie

Joined: Thu Jan 13, 2005 6:24 pm
Posts: 12
I've looked at the forumns and Hibernate-in-action book but I seem to not be able to figure out how to do something that seems should be simple. I have a simple table that maps persons to groups..

person_to_group
fk person_id references persons
fk group_id references groups

groups
pk id
name

persons
pk id
name


Now it seems to me that I should be able to do something like...

person_to_group=new PersonToGroup();
person_to_group.setPersonId=(5);
person_to_group.setGroupId=(6);

However the PersonToGroup is mapped with a many-to-one associations to
person and group, so all I have is setters and accessor that take/return Person or Group objects. This is good when I'm navigating the oject graph... but when I just one to insert a relationship into the database I would now have to fetch the Person and Group object by identifier and then set them on the PersonToGroup object. These two extra database SELECTS are completely unecessary since I already know the identifiers and I don't need any additional data in order to persist the PersonToGroup object. Can anyone give me some pointers on this issue?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.