Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mapping a qualified association with Hibernate

 
Rickard Sundin
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would be the preferred way (or your preferred way) to declare a qualified association in Hibernate (e.g. as described by the UML notation below)?



Any ideas or suggestions?

Best regards
/Rickard
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For something more or less the same I have used component mapping.

But what I was wondering is: doesn't your model fit the Order 1-N OrderLine, OrderLine 1-N (or 1-1?) Product?

/pope
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my opinion,

So orderID determines the relation between the two tables.

This is the table structure should be follow as:


Order (orderID, orderdate);

OrderLine (orderID, lineNumber, description);


On each order can be many order lines. Each order line belongs to precisely 1 order. So there is a one to many (?1 to n? or ?1:n?)
relationship between Order and OrderLine.


So, relation between order and orderline is 1 : N


Mapping File

 
Rickard Sundin
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to enforce that all access to OrderLine (from Order) is indexed by Product. The system could be restricted to only one OrderLine per Product (0..1) or allow multiple OrderLines per Product (0..*).

Could component mapping help me to accomplish that?

/Rickard
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When mapping a collection (the relation Order - OrderLine) you can define sort or an order-by attribute (see Hibernate2 reference: Collection mapping).

Is this what you are looking for?

/pope
 
Rickard Sundin
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my case, Product is not an attribute of Order nor OrderLine, but rather a key that indexes each OrderLine (or set of OrderLines). After Pope mentioning Component Mapping I've been re-reading that secion in Hibernate Reference Documentation. I think perhaps composite-index is what I'm looking for.

Thanx!
/Rickard
[ September 01, 2004: Message edited by: Rickard Johansson ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic