-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate: one-to-one composite foreign key : Strange Scenar
PostPosted: Tue Mar 24, 2009 11:03 am 
Beginner
Beginner

Joined: Wed Aug 22, 2007 5:53 am
Posts: 38
I have 2 classes viz. Product and ProductBasic which has one-to-one relationship.
Product is mapped to a table PRODUCT which has PRODUCTID as PK.
ProductBasic is mapped to a table PRODUCTBASIC which has PRODUCTID,USETYPE and STARTTTIMESTAMP as composite key. Also PRODUCTID
is the foreign key referencing PRODUCT table...

When i am saving Product (with cascade for ProductBasic):
For Product, it's taking persister.identifierType as org.hibernate.type.CustomType
For ProductBasic, it's taking persister.identifierType as org.hibernate.type.ComponentType

Assume productId='1'
When i call session.save(product),
a) For Product: it tries to find hashmap of id=1 using org.hibernate.type.StringType.getHashCode() which comes out to be 49 (ASCII)..
b) For ProductBasic: it tries to find hashmap of id=1 using org.hibernate.type.ComponentType.getHashCode() and throws exception:
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.tietoenator.lis.db.impl.product.bo.CompProductBasicBO.useType

Does it treating ProductBasic as component because it's productId value depends upon Product.productId? Even if it treats
ProductBasic as component, why it is not fetching the proper hashCode() and throwing exception?

Code:
class ProductBO{
private TrimmedStringValue productId;
private ProductBasicBO productBasic;
}


ProductBasic{
  private CompProductBasicBO compProductBasicBO;
  ProductBO productBO;

}

public class CompProductBasicBO implements Serializable {
   private TrimmedStringValue useType;
   private TimeStamp startTimeStamp;
   private ProductBO productId;
}

<class name="ProductBO" table="TBPRODUCT"  optimistic-lock="version">

      <id name="productId" type="com.tietoenator.lis.common.db.data.DbTrimmedStringValue" length="4" column="PRODUCTID">
         <generator class="assigned" />
      </id>
</class>

<class name="com.tietoenator.lis.db.impl.product.bo.ProductBasicBO" table="TBPRODUCTPERIOD" optimistic-lock="version">
   
       <composite-id name="compProductBasicBO" class="com.tietoenator.lis.db.impl.product.bo.CompProductBasicBO">
     
         <key-property name="useType" column="USETYPE" type="com.tietoenator.lis.common.db.data.DbTrimmedStringValue" length="3"></key-property>

         <key-property name="startTimeStamp" column="STARTTIMESTAMP" type="com.tietoenator.lis.common.db.Db2Timestamp" ></key-property>
         <generator class="foreign">
             <param name="property">productBO</param>
           </generator>          

      </composite-id>
      
      <many-to-one name="productBO" class="ProductBO" column="PRODUCTID" />
/>   

[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.