-->
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: Problem mapping complex keys
PostPosted: Mon Mar 26, 2007 11:51 am 
Newbie

Joined: Tue Mar 20, 2007 11:48 am
Posts: 11
Hi,

I'm having a Hibernate mapping file in which I would like to change the composite key (containing 2 long values) in such a way that it maps the id's to complex types.
Let me illustrate this with my mapping files:


hireDetails.hbm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="libraryImpl">
   
<class name="HireDetailsImpl" table="hireDetails">
   <composite-id>
      <key-property name="itemId" type="long" column="itemId" />
      <key-property name="userId" type="long" column="userId" />   
   </composite-id>
   <property name="startDate" type="date" column="startDate" />
   <property name="endDate" type="date" column="endDate" />
</class>
   
</hibernate-mapping>


itemId and userId should be mapped to a class Item and a class User, which are 2 attributes of the hireDetails class.


item.hbm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="libraryImpl">
   
<class name="ItemImpl" table="items">
   <id name="id" type="long" column="id" unsaved-value="-1">
      <generator class="native" />
   </id>
   <property name="title" type="string" column="title" />
   <property name="author" type="string" column="author" />
   <property name="publisher" type="string" column="publisher" />
   <property name="description" type="string" column="description" />
   <property name="technologies" type="string" column="technologies" />
   <property name="comments" type="string" column="comments" />
   <many-to-one name="type" class="TypeImpl" column="typeId" lazy="false" />
   <bag name="hireDetails" cascade="all" lazy="false">
      <key column="itemId" />
      <one-to-many class="HireDetailsImpl" />
   </bag>
   <property name="quantity" type="integer" column="quantity" />
</class>
   
</hibernate-mapping>



Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 27, 2007 3:17 am 
Newbie

Joined: Tue Mar 20, 2007 11:48 am
Posts: 11
Someone who can give me some help here ?


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.