aspose file tools*
The moose likes Object Relational Mapping and the fly likes Legacy and Hibernate1-2-M Mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Legacy and Hibernate1-2-M Mapping" Watch "Legacy and Hibernate1-2-M Mapping" New topic
Author

Legacy and Hibernate1-2-M Mapping

Trung Nguyen
Greenhorn

Joined: Jun 08, 2007
Posts: 1
Hello All, I am a newbie to Hibernate a month ago and very excited to apply the latest&greatest to my new project which I have to access to the legacy database. Been reading lots of forums and still not be able to find the solution to my mapping issues. Exciting still and hopeful still that helps are coming. Here is my mapping issues.

TableA
- column 1
- column 2
- column 3
.....more columns
column 1,2 are the primary keys

TableB
- column 1
- column 2
.... more columns
column 1,2 are the primary keys

TableA is 1-2-Many association TableB

To retrieve TableB records, I have to use the TableA(column 3)to map to TableB(column1)(no mapping needed for TableB(column 2) for record retrieval, but for record insertion, I do).

How should I go about mapping the TableA,TableB?

After nights(3) of sleepless, I am thinking about...no mapping for TableA/TableB at all, I will have to query the TableB as a separate step, meaning, after retrieval the TableA record, I will use the TableA(column 3) to query the TableB. Is this an acceptable solution?

Here is my not-working mapping hbm.xml files:
********************************************
<class name="User" table="A"
dynamic-update="true" optimistic-lock="version">
<meta attribute="class-description">
Represents a User for the WASD web site.
@author trungu
</meta>
<meta attribute="implement-equals">true</meta>
<meta attribute="implement-tostring">true</meta>
<composite-id name="id" class="ClassA">
<key-property name="acctId" type="string" column="1"
length="10">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</key-property>
<key-property name="userId" type="string" column="2"
length="16">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</key-property>
</composite-id>
<property name="userClass" column="3" type="string"
length="5" unique="true"/>

<set name="userFunction" inverse="true">
<key column="1"/>
<one-to-many class="ClassB"/>
</set>
*******************************************************
<class name="UserFunction" table="B" dynamic-update="true"
optimistic-lock="version">
<meta attribute="class-description">
Represents a UserFunction for the WASD web site.
@author trungu
</meta>
<meta attribute="implement-equals">true</meta>
<meta attribute="implement-tostring">true</meta>
<composite-id name="id" class="ClassB">
<key-property name="usrClassId" type="string" column="1"
length="5">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</key-property>
<key-property name="functionId" type="string" column="2"
length="3">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</key-property>
</composite-id>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Legacy and Hibernate1-2-M Mapping