views:

528

answers:

2

I have a class A that has a set of B's. However, these two objects are linked by fields that are NOT the primary key.

For B, I can use , but how do I specify that the join should be in A.secondary_column, Not A. table_primary_key_id ?

<class table="a">
    < id column="table_primary_key_id"  >
    < /id>
    <property column="secondary_column" />

     <set table="B" lazy="false" >
 <key column="B_not_primary" />
 <one-to-many class="BClass" />
  </set>
 </class>
A: 

Solved with

<set name="someSet" table="B" lazy="false"> <key column="B_not_primary" property-ref="secondary_column" /> <one-to-many class="BClass" /> </set>

Sergio Vera
A: 

Hey, i have a similiar problem, except in my case the one-to-many is self-referring, i.e. A and B are actually of the same type (residing in the same table). I'm getting an error saying 'Cast is not valid' when my mapping looks like this:

<set name="someSet" table="A" lazy="false"> 
     <key column="a_not_primary" property-ref="a_not_primary" /> 
     <one-to-many class="AClass" /> 
</set>

because it seems that the join NHibernate is trying to make is between the PRIMARY KEY and the 'secondary' column, which are of type String and Int32 respectively, instead of joining the secondary column to itself.

Any ideas please?

Harel Moshe
Since it's not an answer to this question, better ask it as a new question instead. More people would see it and try to answer...
sth
Sorry... thanks for the correction.
Harel Moshe
Yeah, good idea. Sorry, I cant help, but i'd recommend pasting the full hibernate stacktrace and log... If there's a cast error... I cant make any assumptions.Cheers!
Sergio Vera