Hello,
I have a situation where I want to do a non-primary key many-to-one between two classes. The relationship between these two classes goes beyond a single property, so I have to express it using column tags which do not have the property-ref attribute.
eg.
Code:
<many-to-one class="ShippingOrder" name="ShippingOrder">
<column name="PICK#" property-ref="PickListNumber"/>
<column name="LINE#" property-ref=LineNumber"/>
<column name="RELEASE" property-ref="ReleaseNumber"/>
</many-to-one>
This is unacceptable mapping.
I (accidently) asked this question in the Hibernate forums and saw that there exists a properties tag where I could create a logical-name for a group of properties, and then use that in the mapping.
eg.
Code:
<many-to-one class="ShippingOrder" name="ShippingOrder" property-ref="logical-name-declared-in-shippingorder.hbml-with-properties-tag">
<column name="PICK#"/>
<column name="LINE#"/>
<column name="RELEASE"/>
</many-to-one>
Does NHibernate exist a method to have this same functionality?
I expanded my brain some and got to the solution of creating a class that defines this relationship (in my case PickListNumber, LineNumber, ReleaseNumber).
Code:
public class ShippingNK
{
public virtual int PickListNumber {get; set; }
public virtual int LineItemSequence {get; set; }
public virtual int ReleaseNumber {get; set; }
}
And then in the shippingOrder.hbm I have:
Code:
<component name="ShippingNK" class="ShippingNK" insert="false" update="false">
<property name="PickListNumber" column="CNKZNB" />
<property name="LineItemSequence" column="CNFCNB" />
<property name="ReleaseNumber" column="CNDRNB" />
</component>
<property name="PickListNumber" column="CNKZNB" />
<property name="LineItemSequence" column="CNFCNB" />
<property name="ReleaseNumber" column="CNDRNB" />
I declared them twice because I want them directly accessible as properties from ShippingOrder class, not as components.
And finally, in the many-to-one hbm class I have:
Code:
<many-to-one class="ShippingOrder" name="ShippingOrder" property-ref="ShippingNK">
<column name="PICK#" />
<column name="LINE#" />
<column name="RELEASE" />
</many-to-one>
And this works. The only downside is I have this useless (logically) ShippingNK property of the ShippingOrder class. I declared it private (probably should do protected virtual?) so I wouldn't ever have to notice it outside of mapping because mapping is all it exists for.
Anyways, short question version:
1) Is there a native NHibernate way to match the Hibernate feature?
2) Is my implementation stupid / wrong that I should care about?
Thanks!