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: many-to-one and property-ref
PostPosted: Wed Nov 26, 2008 9:39 am 
Newbie

Joined: Tue Nov 25, 2008 5:23 pm
Posts: 4
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!


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.