-->
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: Problem loading collection property with native sql
PostPosted: Thu May 12, 2011 4:42 pm 
Newbie

Joined: Thu May 12, 2011 4:26 pm
Posts: 2
Hello,

I am hoping someone here can help as i am at my wits end. I am trying to map a one-to-many relationship between two tables that have composite primary keys using native sql as no foreign key relationship exist between the two tables. Please not this is a legacy schema that i cannot change

From hibernate documentation it seems this should be possible but when i put a set mapping similar to what is in the link below:
http://docs.jboss.org/hibernate/core/3. ... l#d0e13732

Something like:

<set name="employments" inverse="true">
<key/>
<one-to-many class="Employment"/>
<loader query-ref="employments"/>
</set>
<sql-query name="employments">
<load-collection alias="emp" role="Person.employments"/>
SELECT {emp.*}
FROM EMPLOYMENT emp
WHERE EMPLOYER = :id
ORDER BY STARTDATE ASC, EMPLOYEE ASC
</sql-query>

I get a mapping exception that the Foreign key must have same number of columns as the referenced primary key
However I cannot really specify a colomn in the key field as there is no foreign key relationship between the two and the relationship is computed by the native sql.

Is it that the documentation is wrong and there HAS TO BE A FOREIGN KEY relationship?

Can someone please advise?!

Thanks,
Buki


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.