-->
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: many-to-many mapping with one side sorted by index needed
PostPosted: Wed Aug 03, 2011 9:17 am 
Newbie

Joined: Wed Aug 03, 2011 7:50 am
Posts: 1
Hi everybody,

I need a many-to-many mapping with one side sorted by index. Sounds simple, but every example I found either went off on a much too complex tangent or ended unfinished.

Basically, I have Parent objects with a list of Children and Child objects with a set of parents. I want to manipulate the list and I want Hibernate to care about the connecting table and the order number.
I found solutions for children with only one parent, but my children have multiple parents and of course a different list position for each parent.
I found solutions for intermediate objects (ParentToChild with parentId, childId, orderNo and various other data), but I don't want a List <ParentToChild>, I want a List<Child>.

Is this possible and how would I have to annotate the methods?

Code:
@Entity
@Table(name="parent")
public class Parent {
   private int id;
   private List<Child> children = new ArrayList<Child>();


   public List<Child> getChildren() {
      return children;
   }

   public void setChildren(List<Child> children) {
           this.children = children;      
   }
}

@Entity
@Table(name="child")
public class Child {
   private int id;
   private Set<Parent> parents = new HashSet<Parent>();


   public Set<Parent> getParents() {
      return parents;
   }

   public void setParents(Set<Parent> parents) {
           this.parents = parents;      
   }
}



Regards, Georg


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.