property-ref support on collection types

Description

It seems like regular Hibernate supports use of the property-ref attribute on the <key/> element inside of a <set/> or other collection type. The basic idea is you point at a foreign key in another table, and it might not join to the primary key of the origin table.

There's not really any good way I can see to solve this mapping problem without this feature.

Environment

None

Attachments

1

Activity

Show:

Daniel Gripca 
November 6, 2009 at 7:29 AM

It seems like it doesn't work if class A has a composite id.
The only change I've made in the test from attachment was adding a composite id to class A and I get this exception:

"NHibernate.Exceptions.GenericADOException: could not initialize a collection:
NHibernate.Bytecode.Lightweight.AccessOptimizer.GetPropertyValues(Object target)"

My mapping:
<class name="Al" table="a" lazy="false">
<!--<id name="Id" column="id">
<generator class="native" />
</id>-->
<composite-id name="CompositeId" class="ACompositeId">
<key-property access="property" column="id" name="Id"/>
<key-property access="property" column="id2" name="Id2"/>
</composite-id>
<property name="Name" column="aname" />
<property name="ExtraIdA" column="extraida" type="string"/>
<bag name="Items" lazy="true" >
<key column="ExtraIdb" property-ref="ExtraIdA" />
<one-to-many class="B" />
</bag>
</class>

Erik Petersen 
July 9, 2009 at 11:25 AM

I can also confirm the test passes.

Fredrik 
April 20, 2009 at 2:59 AM

I can confirm that this is fixed in 2.1.0.Alpha2

Amr Noaman 
June 28, 2008 at 6:38 AM

I have prepared this test case to show the error. The set key column is not the id and it is linked to a foreign key. So, neither key's of the parent nor the child are involved in this one-to-many relationship.

Jeff Gabhart 
June 20, 2008 at 2:18 PM

This is a must-have for those us who have to deal with legacy data.
Here is a link to the Hibernate doc.
http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-declaration-key

Fixed

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created March 27, 2008 at 8:38 AM
Updated November 6, 2009 at 7:29 AM
Resolved July 9, 2009 at 11:27 AM
Who's Looking?