-->
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.  [ 4 posts ] 
Author Message
 Post subject: Mapping multiple One2Many relationships
PostPosted: Tue Dec 20, 2005 1:25 pm 
Newbie

Joined: Tue Dec 20, 2005 7:22 am
Posts: 5
Hello.
I have two classes, which references another class in an One2Many-relationship

Code:
public class A {
  private Object id;
  List<X> xes;
}

public class B {
  private Object id;
  List<X> xes;
}

public class X {
  private Object id;
  private String name;
}


I map this model with three entity tables (for A, B and X) and two join tables A2X and B2X.

What I want to do now, is accessing the class X via a map:

Code:
public class A {
  private Object id;
  Map<String, X> xes;
}

public class B {
  private Object id;
  Map<String, X> xes;
}


where the key of the map is the name of the X object.
How can I do this?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 6:24 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
use map with a map-key element in your hibernate mapping

http://www.hibernate.org/hib_docs/v3/reference/en/html/collections.html#collections-mapping


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 7:13 pm 
Newbie

Joined: Tue Dec 20, 2005 7:22 am
Posts: 5
anar wrote:


This doesn't work for me. When you use map and map-key, the key of the map goes into the association table, and not in the table of the referenced element.
Any other suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 8:52 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Let's see if I'm understanding this correctly. We can ignore class B, whatever holds for the A : X relationship will hold for the B : X relationship. You have table A, with an ID; table X, with an ID and a name; and table A2X, with A's IDs and X's IDs. You want a Map<String, X> in each object of class A, where the key is a property of X, but not its ID?

If I've got that right, I'm not sure that hibernate can help you. I've certainly never seen an example of anything like that. I'd probably tackle that one by sticking with the List<X> in A, and writing a new subclass of AbstractMap which is backed by the List. The new Map class can handle looking stuff up by name.


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