• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about one-to-many reverse: not good idea ?

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I browse the Hibernate offical website. I found an interesting post. I copy it here. That topic is about one-to-many reverse. the link is http://www.hibernate.org/155.html. but nobody discuss that thread.

What is your idea about this post?

======================
is it a stupid idea to do the reverse setter call on the side where
invers="true"? something like:

class Y {
java.util.Set xs;
void addX(X x) {
xs.add(x);
x.addY(this);
}
}

class X {
java.util.Set ys;
void addY(Y y) {
ys.add(y);
}
}

to keep the collections correct?
=======================
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since both sides manage a Set of related objects, this is a many-to-many relationship. To make it one-to-many, replace "Set ys" with "Y y" in class X and change addY(Y y) to setY(Y y). This is how I have my one-to-many relationships set up, and it seems to work fine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic