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.  [ 3 posts ] 
Author Message
 Post subject: Tips on how to create PK's for collections in an entity?
PostPosted: Thu Oct 04, 2007 2:23 pm 
Newbie

Joined: Wed Oct 03, 2007 12:28 pm
Posts: 15
I've searched/googled everywhere and I can't seem to find this answer.

I have an entity, that contains a list of objects (100's). I want to persist this entity to the database but these 100 objects are not going to have unique ids compared to the id's of the objects in another entity, just unique in it's own parent entity.

I don't want to use a sequence to auto-generate the ids because that will be 100's of "next_val" calls that will slow the persistence down. Combine that with 1,000's of entity that will be persisting at least once a day and your talking 100's of 1,000's of "next_val" calls!

Isn't there a way to have the primary key of these objects be the primary key of the parent entity combined with, say, an id of the object (that is unique in the entity)? So, for example, lets say you have Entity Foo, with ID "abc" which contains a list of Bar. One of these Bar, has an ID of "def". Then, you could simply have the primary key of Bar "abc.def".

This seems like something many people would want to do...why does it seem so difficult to do so?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 05, 2007 1:50 am 
Newbie

Joined: Thu Oct 04, 2007 5:00 am
Posts: 13
I can't understand your problem. Could you please tell us your problem in detail ie the table and its fields etc?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 05, 2007 9:19 am 
Newbie

Joined: Wed Oct 03, 2007 12:28 pm
Posts: 15
I figured it out.

My problem was that I wanted to persist a bunch of entities, with unique ID that contained other entities, that did not have unique IDs. I was trying to find a way to assign them unique IDs by using a combination of their parent entity's ID with their own.

Instead, I just learned about "Embedded" objects. These are components instead of entities, so they share the same life-cycle with their parent, do not require unique ID's, etc.


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