-->
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.  [ 8 posts ] 
Author Message
 Post subject: composite-id relation. Almost I have already arrived
PostPosted: Fri Apr 30, 2004 3:19 am 
Newbie

Joined: Thu Apr 29, 2004 9:25 am
Posts: 6
Location: Castellon - Spain
Hello, I have a parent/child relation ( Customer/Order ) with composite id. My schema is this :

CUSTOMERS :

COMPANY_CODE
CUSTOMER_ID
CUSTOMER_NAME


ORDERS :

COMPANY_CODE
ORDER_ID
DATE
CUSTOMER_ID



<hibernate-mapping>

<class name="business.Customer" table="CUSTOMERS">

<composite-id>
<key-property name="companyCode" column="COMPANY_CODE"/>
<key-property name="customerId" column="CUSTOMER_ID"/>
</composite-id>

<property name="name"/>

<set name="orders" inverse="true" lazy="true">
<key>
<column name="COMPANY_CODE"/>
<column name="CUSTOMER_ID"/>
</key>
<one-to-many class="business.Order"/>
</set>

</class>

<class name="business.Order" table="ORDERS">

<composite-id>

<key-property name="companyCode" column="COMPANY_CODE"/>
<key-property name="orderId" column="ORDER_ID"/>

</composite-id>

<property name="date"/>

<many-to-one name="customer" insert="false" update="false">
<column name="COMPANY_CODE"/>
<column name="CUSTOMER_ID"/>
</many-to-one>



</class>


</hibernate-mapping>


Inserting a Order work, but CUSTOMER_ID is ZERO. This is because <many-to-one name="customer" insert="false" update="false">. But if I remove insert="false" and update="false" I get this Error :

net.sf.hibernate.MappingException: Repeated column in mapping for class business.Order should be mapped with insert="false" update="false": COMPANY_CODE


Could you tell me how can I solve this problem

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 30, 2004 12:30 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
This is a common problem with composite ids in hibernate, and one reason I don't use them anymore.

Your column reference in the customer many-to-one in the business.Order class will have to be to a different column than COMPANY_CODE. That's already being used in the composite-id. Try something like CUTOMER_COMPANY_CODE. It will have the same data as COMPANY_CODE. Yes, I know this is redundant and breaks normalization.

Gavin has said many times that this is a difficult problem to get around and it won't be fixed any time soon.

http://forum.hibernate.org/viewtopic.php?t=925446
http://forum.hibernate.org/viewtopic.php?t=927698


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 02, 2004 7:35 am 
Newbie

Joined: Thu Apr 29, 2004 9:25 am
Posts: 6
Location: Castellon - Spain
Ok, my problem is that I've got a Legacy system database, all tables had already been created, and I can't change their structure. So, this will not be solutioned ???

Very thanks for your replies


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 02, 2004 5:32 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Quote:
So, this will not be solutioned ???

That's my guess. You can create a JIRA request, but it would probably be rejected. The Hibernate team seems pretty opposed to composite id's in general, so I doubt they'd expand much on features involving them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 2:33 pm 
Newbie

Joined: Thu Apr 29, 2004 9:25 am
Posts: 6
Location: Castellon - Spain
ok, thanks for your reply. Do you think that with JDO I can solve this problem ???

Thank you very much


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 2:47 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
How should we know?

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 4:38 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Sorry, jlm. I haven't used JDO so I don't know.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 7:44 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Keep many-to-one insert and update false
And add a property mapping CUSTOMER_ID to customerId
Then fill it manually or write a smart non mapped setter filling it.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.