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.