-->
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.  [ 2 posts ] 
Author Message
 Post subject: OneToOne or OneToMany?
PostPosted: Thu Jul 20, 2006 10:56 am 
Newbie

Joined: Wed Jul 19, 2006 9:03 pm
Posts: 1
Greetings,

I'm new to Hibernate so I may be approaching this problem completely wrong. The relationship I want to model is described below - ClassA contains exactly 3 references to ClassB:

Code:
Class A {
  ClassB x;
  ClassB y;
  ClassB z;
}

Class B {
  ClassA a;
}


I don't think I can implement this as @OneToOne because x,y, and z would all be related to a. But, I don't know how to make this a @OneToMany either since x,y and z are not part of a collection.

Is this proper technique for modeling such a relationship to convert my x, y, and z elements into a collection of ClassB? Or is there a way I can maintain an explicitly bounded multiplicity (i.e. 1 to 3 instead of just 1 to many)?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 5:02 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Let's assume that x is the birirectional version of a, and y and z anre unrelated

Code:
Class A {
  @ManyToOne @JoinColumn(name="x_b_id")
  ClassB x;
  @ManyToOne @JoinColumn(name="y_b_id")
  ClassB y;
  @ManyToOne @JoinColumn(name="z_b_id")
  ClassB z;
}

Class B {
  @OneToOne(mappedBy="x"
  ClassA a;
}

_________________
Emmanuel


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