As an aside:

<property name="PaymentId" column="paymentId" insert="false"
update="false" />
<many-to-one name="Payments" column="paymentId" cascade="save-update"
not-null="true"  />

I have this pattern a ton in my mappings.  Some reasons:

- use of natural keys everywhere (OrderNumber is PK and business
meaning) ... not a real reason, but causes all of the trouble
basically.
- key-many-to-one can be a pain sometimes ... can't remember a good
example as I've stopped using it (so I map a property as PK and then
the relationship with insert/update false).
- composite primary keys can't be lazy loaded (Order -> Item requires
two columns relationship and I want to iterate through 1000 Orders
showing ItemNumber, 1 of the PK, would do N+1 without dual mappings).
- relationships aren't guaranteed to last depending on entity state
(Order processed goes to history, but I still require to show the
number to the user)

Sucks.

On Jul 24, 8:56 am, Dimitris Andrakakis <[email protected]> wrote:
> Ok, I figured it out myself. The problem was the column name :
>
> <many-to-one name="ArrivalLandingTypeId" access="property"
>   class="OlympicHandling.Oly.ObjectModel.LandingType,
>   OlympicHandling.Oly.ObjectModel" column="LandingTypeId" foreign-
>   key="FK_LandingType_FlightEntry_Arrival" fetch="join" lazy="proxy" /
>
> <many-to-one name="DepartureLandingTypeId" access="property"
>   class="OlympicHandling.Oly.ObjectModel.LandingType,
>   OlympicHandling.Oly.ObjectModel" column="LandingTypeId" foreign-
>   key="FK_LandingType_FlightEntry_Departure" fetch="join"
> lazy="proxy" />
>
> Notice the "column="LandingTypeId" which is the same for both.
> Ofcourse this is incorrect. BTW this hbm.xml is auto-generated (I'm
> using Castle ActiveRecord).
>
> The correction is this :
>
> <many-to-one name="ArrivalLandingTypeId" access="property"
> class="OlympicHandling.Oly.ObjectModel.LandingType,
> OlympicHandling.Oly.ObjectModel" column="ArrivalLandingTypeId" foreign-
> key="FK_LandingType_FlightEntry_Arrival" lazy="proxy" />
>     <many-to-one name="DepartureLandingTypeId" access="property"
> class="OlympicHandling.Oly.ObjectModel.LandingType,
> OlympicHandling.Oly.ObjectModel" column="DepartureLandingTypeId"
> foreign-key="FK_LandingType_FlightEntry_Departure" lazy="proxy" />
>
> In ActiveRecord, this means setting the Column= attribute :
>
>         private LandingType _ArrivalLandingTypeId;
>         [BelongsTo("LandingTypeId", Column="ArrivalLandingTypeId",
>             ForeignKey = "FK_LandingType_FlightEntry_Arrivalival")]
>         public LandingType ArrivalLandingTypeId
>         {
>             get { return _ArrivalLandingTypeId; }
>             set { _ArrivalLandingTypeId = value; this.OnSetProperty
> (); }
>         }
>
> and
>
>         private LandingType _DepartureLandingTypeId;
>         [BelongsTo("LandingTypeId", Column="DepartureLandingTypeId",
>             ForeignKey =
> "FK_LandingType_FlightEntry_Departurearture")]
>         public LandingType DepartureLandingTypeId
>         {
>             get { return _DepartureLandingTypeId; }
>             set { _DepartureLandingTypeId = value; this.OnSetProperty
> (); }
>         }
>
> Thank you for your response !
>
> Dimitris
>
> On 24 Ιούλ, 15:34, Fabio Maulo <[email protected]> wrote:
>
>
>
> > mmmm same table ok but probably different types, right ?same origin + same
> > type mean same object instance.
>
> > 2009/7/24 Dimitris Andrakakis <[email protected]>
>
> > > Hi there,
>
> > > The first example isn't mine; it is from a post where the problem is
> > > described :
>
> > >http://codeverity.com/timweaver/nhibernate-invalid-index-for-this-sql...
>
> > > And no, I don't understand the reason either.
>
> > > The second part, with the landing types is *my* problem.
>
> > > Dimitris
>
> > > On 24 Ιούλ, 13:15, Fabio Maulo <[email protected]> wrote:
> > > > CuriosityWhich is the reason to do something like this ?
> > > > <property name="PaymentId" column="paymentId" insert="false"
> > > update="false"
> > > > />
> > > > <many-to-one name="Payments" column="paymentId" cascade="save-update"
> > > > not-null="true"  />
>
> > > > 2009/7/24 Dimitris Andrakakis <[email protected]>
>
> > > > > Hi all,
>
> > > > > First post here; I did my homework before posting, but please excuse
> > > > > me if I'm missing something.
>
> > > > > Here's the problem : I'm getting the message "Invalid index 30 for
> > > > > this SqlParameterCollection with Count=30". As I've read from various
> > > > > postings, the usual reason is having a class which has a mapping to
> > > > > another class AND one of its columns, like this (copy-paste from
> > > > > another post) :
>
> > > > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
> > > > >    schema="TestDB.dbo"
> > > > >    namespace="Domain.Foo"
>
> > > > >  <class name="Domain.Foo.ProfileP, Domain" table="ProfileP"
> > > > > lazy="false" >
> > > > >    <id name="ID" column="ID" type="Int32" unsaved-value="0">
> > > > >      <generator class="native" />
> > > > >    </id>
> > > > >    <property name="ProfileId" column="profileId" type="Int32" />
> > > > >    <property name="PaymentId" column="paymentId"   type="Int32"
> > > > > insert="false" update="false" />
> > > > >    <many-to-one name="Payments" class="Domain.Foo.Sub, Domain"
> > > > > column="paymentId" cascade="save-update" not-null="true"  />
> > > > >  </class>
> > > > > </hibernate-mapping>
>
> > > > > Here, the problem is clear. In my situation though, the problem is
> > > > > this :
>
> > > > > [...]
> > > > >    <many-to-one name="ArrivalLandingTypeId" access="property"
> > > > > class="OlympicHandling.Oly.ObjectModel.LandingType,
> > > > > OlympicHandling.Oly.ObjectModel" column="LandingTypeId" foreign-
> > > > > key="FK_LandingType_FlightEntry_Arrival" fetch="join" lazy="proxy" />
> > > > >    <many-to-one name="DepartureLandingTypeId" access="property"
> > > > > class="OlympicHandling.Oly.ObjectModel.LandingType,
> > > > > OlympicHandling.Oly.ObjectModel" column="LandingTypeId" foreign-
> > > > > key="FK_LandingType_FlightEntry_Departure" fetch="join" lazy="proxy" /
>
> > > > > I can see where the problem is BUT this situation is legitimate; I
> > > > > have TWO columns (ArrivalLandingTypeId, DepartureLandingTypeId) and
> > > > > their values must be from the same table (LandingType).
>
> > > > > Is there any way or workaround out of this ?
>
> > > > > TIA,
>
> > > > > Dimitris Andrakakis
>
> > > > --
> > > > Fabio Maulo- Απόκρυψη κειμένου σε παράθεση -
>
> > > > - Εμφάνιση κειμένου σε παράθεση -
>
> > --
> > Fabio Maulo- Απόκρυψη κειμένου σε παράθεση -
>
> > - Εμφάνιση κειμένου σε παράθεση -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to