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]