-->
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.  [ 4 posts ] 
Author Message
 Post subject: Mapping to a non-primary key of Parent table.
PostPosted: Thu Dec 27, 2007 3:33 am 
Newbie

Joined: Sat Oct 20, 2007 2:43 am
Posts: 11
Hi All,


I am facing one problem, I have tried alll forums but did't get the solution.

Example:-

I have following classes: Person,CompanyDetails,Ocupation and tables: PERSON, COMPANY, COMPANY_DETAILS, OCCUPATION
Person class has following mapping :

<many-to-one name="ocupation" column="OCC_ID" lazy="false" not-null="true"/>

<set name="companyDetails" table="COMPANY" schema="x" lazy="false" fetch="join">
<key column="PERSON_OCC_ID" property-ref="ocupation">
<many-to-many class="com.company.CompanyDetails" column="DETAIL_ID">
</set>

Now my set which is company details , it points to a table COMPANY which has a column PERSON_OCC_ID which is a foregin key to PERSON table's OCC_ID(which is a non-primary key of PERSON table). SO, I am using property-ref in the key column. But this is giving ClassCastException, Becuase it's fetching Ocupation istead of CompanyDetails. If I remove property-ref it's comparing with the primary key of PERSON table, which is not my requirement


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 27, 2007 8:46 pm 
Beginner
Beginner

Joined: Tue Oct 30, 2007 7:57 am
Posts: 47
About this line:

<many-to-one name="ocupation" column="OCC_ID" lazy="false" not-null="true"/>

Shouldn't it hava a class attribute

About the column PERSON_OCC_ID: Is it also a foreign key to table OCCUPATION, or is only a property. In the second case, I think you are comparing an Occupation entity (The property ocupation), to wathever you have in the company table

Please, post also the mapping of the CompanyDetails class. That might help a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 28, 2007 2:42 am 
Newbie

Joined: Sat Oct 20, 2007 2:43 am
Posts: 11
About this line:

<many-to-one name="ocupation" column="OCC_ID" lazy="false" not-null="true"/>

if it is in the same package then I think it doesn't require it. Because it's working fine.


About the column PERSON_OCC_ID: It a foreign key to the table PERSON not OCCUPATION, But the only thing is this FOREIGN KEY refers to a non-primary key of PERSON table that is why I am companring it with the property occupation in the company table.


There is nothing important in the CompanyDetails class which can help you still I am posting the mapping for this

<id column="DETAIL_ID">
<property name="location" column="comp_location">
<property name="name" column="comp_name">


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 28, 2007 10:25 am 
Regular
Regular

Joined: Sat Nov 25, 2006 11:37 am
Posts: 72
At database level a foreign key by definition has to reference a primary key or a unique constraint. However, at the ORM level I believe all references must be to the id property of the referenced entity, that is mapping of foreign keys based on unique constraints back into the ORM world is not supported. This is because an entity only has a single identity and a database level unique constraint is not be reflected at the entity level as an alternate id.


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