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#d0e13732Something 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