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: Advanced Hibernate Mapping
PostPosted: Thu Sep 10, 2009 5:00 pm 
Newbie

Joined: Thu Feb 05, 2009 4:17 pm
Posts: 8
I have 2 questions.
The first question is:
JobCart:
ID (PK)
HeatKitModel (FK) - to HeatKits table, ItemNumber column
ProductID (FK) - to Product table

Product:
ID (PK)
HeatKitTableName (FK) - to HeatKits table, TableName column

HeatKits:
TableName (PK)
ItemNumber (PK)
HeatingOption (FK)

How can I write a mapping for JobCart (especially if I want to have a HeatKit object inside of JobCart)?
The other key to HeatingOption table is in the Product table.
Code:
<hibernate-mapping>
   <class name="com.abc.JobCart" table="lcpjbcp">
      <id name="id" column="ID" unsaved-value="0">
         <generator class="native" />
      </id>
      <many-to-one name="product"
         class="com.abc.Product" column="productId"
         not-null="true" fetch="join" lazy="false" />
   </class>
</hibernate-mapping>


Second question is:
HeatKits has a one-to-one relationship with HeatingOption table through heatingOption column (FK).
However, HeatingOption has 2 PK (Composite Key) - ID and type.
The database designer says that all HeatKit will always have type="ELE", so no need to repeat the column.
How can I have a HeatingOption object inside of the HeatKit object?
Currently, I just grab the heatingOption as a string, and then run another query to get the HeatingOption object.

Code:
<hibernate-mapping>
   <class name="com.abc.HeatKit" table="lcphktp">
      <composite-id>
         <key-property name="tableName" />
         <key-property name="itemNumber" />
      </composite-id>
      <property name="heatingOption"/>
   </class>
</hibernate-mapping>

<class name="com.abc.HeatingOption"
      table="lcphopp">      
      <composite-id>
         <key-property name="id" />         
         <key-many-to-one name="heatingType"
            class="com.abc.HeatingType"
                column="type" lazy="false"/>
      </composite-id>   
      <property name="description" />
   </class>


Top
 Profile  
 
 Post subject: Re: Advanced Hibernate Mapping
PostPosted: Fri Sep 11, 2009 11:19 am 
Newbie

Joined: Thu Feb 05, 2009 4:17 pm
Posts: 8
I spent few hours extra digging through the forums and miraculously, I found similar question that was posted by someone else: viewtopic.php?t=945130
After trying out the suggestion on that post, I came up with this mapping, and it worked! It solved question no2.
Code:
<one-to-one name="heatingOption"
   class="com.abc.HeatingOption"
   foreign-key="heatingOption" >
      <formula>heatingOption</formula>
      <formula>'ELE'</formula>
</one-to-one>


I will read further to try to solve question no1.


Top
 Profile  
 
 Post subject: Re: Advanced Hibernate Mapping
PostPosted: Fri Sep 11, 2009 3:44 pm 
Newbie

Joined: Thu Feb 05, 2009 4:17 pm
Posts: 8
I think I may need something like this:
Code:
<hibernate-mapping>   
   <class name="com.goodman.litconfig.model.JobCart" table="lcpjbcp">
      <id name="id" column="ID" unsaved-value="0">
         <generator class="native" />
      </id>
      <one-to-one name="heatKit"
         class="com.goodman.litconfig.model.product.HeatKit">
         <formula>(select p.heatKitTable from WEBDATA.LCPPRDP p, WEBDATA.LCPJBCP jc where jc.productId = p.id)</formula>
         <formula>heatKitModel</formula>         
      </one-to-one>
   </class>
</hibernate-mapping>


However, when I ran the query, it reported an error: [SQL0811] Result of SELECT more than one row.
I checked my data, each LCPJBCP (JobCart) can only have 1 product, and each product can only have 1 heatKitTable.
Could anyone point me to the right direction?


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