-->
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: set insertion with composite-id
PostPosted: Mon Dec 15, 2003 5:35 pm 
Newbie

Joined: Mon Dec 15, 2003 3:37 pm
Posts: 3
I have an object, say a person, and the db has a list of foods that a person might eat in another table. The table that holds person ids and food ids has no primary key, so I'm using a composite-id of person id and food id.

In the program I want to add/change the foods a person might eat by creating a set of food items and then persisting the person. From what I've read, I need to implement hashCode() and equals(), which I've done. With just those things done, persisting the person leads to hibernate updating the PersonFood objects in the set, not inserting. I have read in the Hibernate docs that I have to implement Interceptor.isUnsaved() in order for it to know whether to update the items or insert. Clearly this means deleting items that are no longer in the set isn't being taken care of either.

Is there a better way than using Interceptor? I'd rather not implement all of its methods. If I do, will it delete the entries that are no longer in the set or will I have to do that myself? Also, does creating an id object have any actual impact. Since the PersonFood object only contains the members that make up its composite-id it seems redundant to create an id object, but the Hibernate docs seem to suggest you need to do it to insert the objects.
Thanks to anyone who can help,
Todd

PS people and food is in fact just the example.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 6:04 pm 
Regular
Regular

Joined: Tue Sep 02, 2003 5:09 pm
Posts: 81
Location: Whitefish Montana
I would consider using a system generated id and treating your composite id as a candidate key. That gets you around the interceptor. If you specify cascade="all-delete-orphan" orphaned foods will be deleted with their associated person.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 12:34 pm 
Newbie

Joined: Mon Dec 15, 2003 3:37 pm
Posts: 3
We are considering using a system generated id, though it's not our preference since there's no reason to have one other than to satisfy hibernate.
I tried using cascade="all-delete-orphan" but it produced an error saying it wasn't a possible value for cascade. Is that for a possibly newer version of hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 1:02 pm 
Newbie

Joined: Mon Dec 15, 2003 3:37 pm
Posts: 3
Actually, could you clarify by what you mean by a system generated id? I assumed you meant a primary key in the db that would be generated there, but if you meant something else (something generated on the code side?) please let me know.


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.