-->
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: one-to-many problem
PostPosted: Thu Feb 19, 2004 6:48 am 
hi all,
I have got a problem on creating the mapping file for my class, after read the documentation, i found a <composite-id> function, but i am not sure how can I use it to write my mapping file for my class.

2 Tables of my Database, which have one-to-many relation and one of the table has 3 keys. AuctionItem one-to-many BidOnItemLog.

AuctionItem Table
=================
auctionid *
createdate
starttime
endtime
startprice
winner

BidOnItemLog Table
=================
auctionid * (FK)
userid *
datetime *
price

My tables relation , the column in BidOnItemLog Table "auctionid" is a foreign key which is related to the primary key of the AuctionItem Table.
and "userid" and "datetime" are the primary key of BidOnItemLog Table.

Mapping file of AuctionItem Domain Object
Code:
<hibernate-mapping>
   <class name="com.twofi.auction.objects.AuctionItem" table="auctionitem">
      <id name="auctionid" column="auctionid" unsaved-value="any">
         <generator class="increment" />
      </id>
      <property name="createdate" column="createdate" />
      <property name="starttime" column="starttime" />
      <property name="endtime" column="endtime" />
      <property name="startprice" column="startprice" />
      <property name="winner" column="winner" />
   </class>
</hibernate-mapping>


Can anyone please kindly to teach me, how can I define the mapping for the BidOnItemLog Objects ?? Thank you very much ! : )


Top
  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 7:01 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Something like that, but read the tutorials and such materials
Code:
<hibernate-mapping>
   <class name="com.twofi.auction.objects.AuctionItem" table="auctionitem">
      <id name="auctionid" column="auctionid" unsaved-value="any">
         <generator class="increment" />
      </id>
      <property name="createdate" column="createdate" />
      <property name="starttime" column="starttime" />
      <property name="endtime" column="endtime" />
      <property name="startprice" column="startprice" />
      <property name="winner" column="winner" />
      <set name="logs" inverse="true">
         <key>
           <column name="auctionid"/>
         </key>

         <one-to-many class="BidOnItemLog"/>
       </set>
   </class>
</hibernate-mapping>

<hibernate-mapping>
   <class name="com.twofi.auction.objects.BidOnItemLog" table="auctionitem">
      <composite-id unsaved-value="any">
         <key-many-to-one column="auctionid" class="Auction"/>
         <key-property name="userid" column="userid"/>
         <key-property name="datetime" column="datetime"/>
      </composite-id>
      <property name="createdate" column="createdate" />
      <property name="starttime" column="starttime" />
      <property name="endtime" column="endtime" />
      <property name="startprice" column="startprice" />
      <property name="winner" column="winner" />
      <set name="logs" inverse="true">
         <key>
           <column name="auctionid"/>
         </key>

         <one-to-many class="BidOnItemLog"/>
       </set>
   </class>
</hibernate-mapping>

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 7:09 am 
thanks emmanuel ! You have gave me a big hint.
I'll try my best to understand it.


Top
  
 
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.