-->
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.  [ 1 post ] 
Author Message
 Post subject: Many-to-Many : mapping without Primary Key class?
PostPosted: Wed Dec 08, 2004 6:05 am 
Beginner
Beginner

Joined: Fri Jun 25, 2004 5:31 am
Posts: 31
Hibernate version:2.1.7c

[Name and version of the database :Oracle 8

I have the following senario and need comments about the mappings:

Quote:
ITEM (ITEM_ID, NAME)
ORDER (ORDER_ID, DESCRIPTION)
ORDER_ITEM (ITEM_ID, ORDER_ID, QTY,PRICE)


My Order.hbm.xml is as follows:

Code:
<hibernate-mapping>
   
   <class name="dao.Order" table="ORDER">
      <id name="id" type="string">
         <column name="ORDER_ID" length="10"/>
         <generator class="assigned"/>
      </id>
      
      <set name="items" table="ITEM_ORDER">         
          <key column="ORDER_ID"/>         
         
          <composite-element class="dao.ItemOrder">           
            <many-to-one name="item" class="dao.Item">             
              <column name="ITEM_ID"/>
            </many-to-one>

            <property name="qty" column="QTY" type="integer"/>
            <property name="price" column="PRICE" type="double"/>
          </composite-element>

        </set>   
              
      <property name="desc" column="DESCRIPTION" type="string"/>
   </class>
</hibernate-mapping>


My Item.hbm.xml is as follows:

Code:
<hibernate-mapping>
      <class name="dao.Item" table="ITEM" >
      <id name="id" type="string">
         <column name="ITEM_ID" length="10"/>
         <generator class="assigned"/>
      </id>
            
      <property name="desc" column="NAME" type="string"/>
   </class>
</hibernate-mapping>


The ITEM_ORDER dao has the setters/getters for :
Item item;
private double price;
private int qty;
- and it doesn't have a seperate hbm.xml since the mapping is embedded inside order.hbm.xml via a <composite-element> tag.

How to enable the composite primary key for the ITEM_ORDER ? withing the <composite-element> the items set has ORDER_ID defined as the key. But how to specify the ITEM_ID as a part of the composite p.key of the ITEM_ORDER ? Can i define it inside the <composite-element> tag?

please help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.