-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate mapping question
PostPosted: Wed Nov 21, 2007 11:18 am 
Newbie

Joined: Wed Nov 21, 2007 11:03 am
Posts: 8
Hi everyone, I'm new to Hibernate and got this problem when trying to map the classes. I have 2 classes UnitDescription and UnitConversion.
UnitDescription has a Map<Integer, UnitConversion> (containing all the conversions it could have).
UnitConversion has 2 attributes 'from' and 'to', both are type UnitDescription (specifying source unit and target unit of conversion).
So the result is some relation 2-to-many, I can't use many-to-one at 'from' and 'to', because doing so will create duplicated columns in table UnitConversion (2 foreign keys with the same names).
Now I don't have any idea how to resolve it. Please give me an advice about this situation.


Top
 Profile  
 
 Post subject: Object Model
PostPosted: Wed Nov 21, 2007 4:22 pm 
Newbie

Joined: Thu Nov 15, 2007 1:36 pm
Posts: 12
Location: Ahsburn, VA
I'm not understanding your object model, because it appears (and I could be wrong) that you're also trying to capture database-like table associations as well.

Ignoring Hibernate for the moment, what do the raw classes look like, and what is the map in UnitDescrption for?

A concrete example like "this is how inches to feet are represented with my classes" would help.

This derived code from your text is confusing to me:
Code:
public class UnitConversion {
  UnitDescription from;
  UnitDescription to;
}

public class UnitDescription {
  Map<Integer, UnitConversion> m = new Map<Integer, UnitConversion>();  // What's this doing?
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 22, 2007 3:37 am 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
The standard aproach for this is to use a List with two elements.


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