-->
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: Object as property when part of key
PostPosted: Mon Mar 01, 2004 2:58 am 
Newbie

Joined: Sat Feb 21, 2004 3:02 pm
Posts: 14
I am finding that Hibernate does a great job of mapping a key to an object when the foeeigh key is a column in hte
table as below where CustomerID maps to CustomerImpl


<class name="com.microsoft.northwind.impl.OrderImpl" table="Orders" >
<id name="OrderID" type="int" unsaved-value="null" >
<column name="OrderID" sql-type="int identity" not-null="true" />
<generator class="hilo" />
</id>
<many-to-one name="Customer" column="CustomerID" class="com.microsoft.northwind.impl.CustomerImpl" not-null="false" />
<many-to-one name="Employee" column="EmployeeID" class="com.microsoft.northwind.impl.EmployeeImpl" not-null="false" />
...
</class>

The problem comes where the properties are part of the key
Below I would like to make OrderID map to OrderImpl and
ProductID map to ProductImpl

<class name="com.microsoft.northwind.impl.OrderDetailImpl" table="Order Details" >
<composite-id >
<key-property name="OrderID" type="int" column="OrderID" />
<key-property name="ProductID" type="int" column="ProductID" />
</composite-id>
<property name="unitPrice" column="UnitPrice" type="double" not-null="true" />
<property name="quantity" column="Quantity" type="int" not-null="true" />
<property name="discount" column="Discount" type="real" not-null="true" />
</class>

any hints as to how

_________________
Steven M. Lewis PhD
4221 105th Ave NE
Kirkland, WA 98033
425-889-2694
206-384-1340 (cell)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 3:29 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
There are two standard ways to do this:

(1) use a <key-many-to-one>
(2) use ordinary <key-properties> and then add extra <many-to-one>s with insert="false" update="false"


If you search the forum you will find examples of these two approaches.


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.