-->
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.  [ 5 posts ] 
Author Message
 Post subject: NHibernate 2Alpha1 Error (Mapping Problem?)
PostPosted: Wed May 07, 2008 3:20 pm 
Newbie

Joined: Wed May 07, 2008 2:56 pm
Posts: 4
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

2.0.0.Alpha1

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="ModelLibrary.Center,ModelLibrary" table="Centers" lazy="true">
<id name="CenterID" column="CenterID" type="System.Int32">
<generator class="native" />
</id>
<property name="ParentID" column="ParentID" type="System.Int32" not-null="false" />
<property name="CenterName" column="CenterName" type="System.String" not-null="true" />
<property name="ZipCode" column="ZipCode" type="System.String" not-null="false" />
<property name="CountyID" column="CountyID" type="System.Int32" not-null="true" />
<property name="StateID" column="StateID" type="System.Int32" not-null="true" />
<property name="CreatedOn" column="CreatedOn" type="System.DateTime" not-null="false" />
<property name="CreatedBy" column="CreatedBy" type="System.String" not-null="false" />
<property name="ModifiedOn" column="ModifiedOn" type="System.DateTime" not-null="false" />
<property name="ModifiedBy" column="ModifiedBy" type="System.String" not-null="false" />
<many-to-one name="LUCounty" class="ModelLibrary.LUCounty,ModelLibrary" column="CountyID" />
<many-to-one name="LUState" class="ModelLibrary.LUState,ModelLibrary" column="StateID" />
<bag name="Referrals" inverse="true" cascade="delete">
<key column="CenterID" />
<one-to-many class="ModelLibrary.Referral,ModelLibrary" />
</bag>
<bag name="Clients" inverse="true" cascade="delete">
<key column="CenterID" />
<one-to-many class="ModelLibrary.Client,ModelLibrary" />
</bag>
<bag name="MMCentersOrganizations" inverse="true" cascade="delete">
<key column="CenterID" />
<one-to-many class="ModelLibrary.MMCentersOrganization,ModelLibrary" />
</bag>
<bag name="UsersInCenters" inverse="true" cascade="delete">
<key column="CenterID" />
<one-to-many class="ModelLibrary.UsersInCenter,ModelLibrary" />
</bag>
<bag name="Organizations" table="MM_Centers_Organizations" cascade="all">
<key column="CenterID" />
<many-to-many column="OrganizationID" class="ModelLibrary.Organization,ModelLibrary" />
</bag>
<bag name="aspnetUsers" table="UsersInCenters" cascade="all">
<key column="CenterID" />
<many-to-many column="UserId" class="ModelLibrary.aspnetUser,ModelLibrary" />
</bag>
</class>
</hibernate-mapping>


I'm getting an "Invalid index 10 for this SqlParameterCollection with Count=10." on session.Flush() and am not quite sure what is going on. I'm pretty new to nhibernate so any help is appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 07, 2008 4:46 pm 
Newbie

Joined: Wed May 07, 2008 2:56 pm
Posts: 4
I've noticed that if I remove the many-to-one mappings that I no longer get the exception. After trying different cascade settings (i.e. cascade="none/all/save-update" i can't get any many-to-one maps to work while persisting. Any thoughts on what's wrong with my many-to-one mapping?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 08, 2008 4:06 am 
Newbie

Joined: Wed May 07, 2008 8:18 am
Posts: 3
Oh,these complicated words really make me crazy always...


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 09, 2008 12:02 pm 
Newbie

Joined: Fri May 09, 2008 10:29 am
Posts: 4
I had the same issue, but my <many-to-one mapping was referencing another property that I was adding as a property as well. My only solution was to remove the property:

<class name="MerchantProduct" table="MerchantProductsRel">
<id name="ID" column="MerchantProductID">
<generator class="identity" />
</id>
<!-- Default to Print category -->
<discriminator formula="case when RootCategoryID is null then 1 else RootCategoryID end" />

<property name="ProductID" type="Int32"/>

<property name="Name" type="String"/>
<property name="SKU" type="String"/>
<property name="Cost" type="Decimal"/>
<property name="SuggestedPrice" type="Decimal"/>
<property name="Active" type="Boolean"/>
<property name="ShipOnly" type="Boolean"/>
<property name="ShippingInfo" type="String"/>
<property name="WholesalerID" type="Int32"/>
<property name="WholesalerSKU" type="String"/>
<property name="SortOrder" type="Int32"/>
<property name="OutputType" type="DataAccess.EProductOutputType, DataAccess"/>

<set name="ProductPricingList" lazy="true" inverse="true">
<key column="MerchantProductID"/>
<one-to-many class="MerchantProductPricing"/>
</set>

<subclass name="MerchantPrint" discriminator-value="1" >
<property name="Height" type="Decimal"/>
<property name="Width" type="Decimal"/>
<property name="RecommendedHeight" type="Int32"/>
<property name="RecommendedWidth" type="Int32"/>
<property name="QuickPicks" type="Boolean"/>
<many-to-one name="BaseProduct" class="Print" column="ProductID"/>
</subclass>
</class>

Here, the ProductID was breaking the save. Seems to be a bug.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 09, 2008 12:59 pm 
Newbie

Joined: Wed May 07, 2008 2:56 pm
Posts: 4
I figured it out after a bit, it was trying to persist the parent object when I saved for some reason...even though cascade was set to none.

So I just inserted:
insert="false" update="false" into the many-to-one map and everything seems fine now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

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.