one-to-one with composite-id must have common CompositeId class
---------------------------------------------------------------
Key: HHH-3993
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3993
Project: Hibernate Core
Issue Type: Improvement
Affects Versions: 3.2.6
Reporter: Sandeep Vaid
I have one-to-one relationship between Product and Product-Id..
I have Product (PId, PDesc) as composite-key
I have ProductBasic (ProductId, ProductDesc) as composite-Key
Case 1: I created one Composite class which is common for both Product and ProductBasic..
class CompProductRelated{
string pid;
string pdesc;
}
then try to fetch Product.. It worked !!!
Case 2: If i create seperate Composite class for Product & ProductBasic viz.
CompProduct and CompProductBasic respectively as :
class CompProduct{
string productId;
string productDesc;
}
and not if i define the mapping accordingly as:
In Product.hbm.xml
<composite-id name="compProduct" class="CompProduct">
<key-property name="pid" type="string"
column="PRODUCTID" length="10"></key-property>
<key-property name="desc" type="string"
column="DESC" length="10"></key-property>
</composite-id>
In ProductBasic.hbm.xml
<composite-id name="compProductBasic"
class="CompProductBasic">
<key-property name="productId" column="PRODUCTID"
type="string" length="10"/>
<key-property name="productDesc" column="DESC1"
type="string" length="10"/>
</composite-id>
Now while fetching Product (and internally it will fetch ProductBasic), it gives the
following exception:
org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class
model.CompProductBasic, got class model.CompProduct
So the only approach for one-to-one with composite-id is to have a common compositeId
class..
The link
http://docs.jboss.org/hibernate/stable/core/reference/en/html_single/#map...
recommends 3 solutions (3rd being to have a common compositeId class) but as per my
understanding 1st and 2nd approach will give exception for one-to-one with composite-id
...
I think this hibenate restriction (of having common CompositeId class for one-to-one
relationship) is not good as it puts a constraint on how domain model (java) should be
which could not be possible everytime in legacy applications..
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira