File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Mapping a qualified association with Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Mapping a qualified association with Hibernate" Watch "Mapping a qualified association with Hibernate" New topic
Author

Mapping a qualified association with Hibernate

Rickard Sundin
Greenhorn

Joined: Mar 10, 2003
Posts: 16
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

Joined: Jul 12, 2004
Posts: 995
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


blog - InfoQ.com
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
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



SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Rickard Sundin
Greenhorn

Joined: Mar 10, 2003
Posts: 16
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

Joined: Jul 12, 2004
Posts: 995
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

Joined: Mar 10, 2003
Posts: 16
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 ]
 
wood burning stoves
 
subject: Mapping a qualified association with Hibernate