-->
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: Mapping same entity to itself as a collection
PostPosted: Mon Sep 26, 2011 2:40 pm 
Newbie

Joined: Mon Sep 26, 2011 2:07 pm
Posts: 3
Ok, say i have a "Friend" entity which needs to have "Friend"s as property
Since this is a many to many connection, If i'd create this schema using SQL (Which i'm not, i'm using the hbm.ddl.auto to do it for me) i'd probably make another table containing 2 columns with 2 ids (1 for each friend)
However, i'm not sure how to annotate this in hibernate, i did this:

class PersonEntity {

.
.

@ElementCollection
private List<PersonEntity> friends ;

.
.
}

Problem is, i'm not sure it's the best way.. for instance, i'm "thinking" that whenever i add a friend to the list and persist it will be inserted as the next row in the table, and since i can't seem to index this field i'm imagining the data retrieval will be inefficient.
Can you suggest better ways to solve this problem?


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.