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: Insert/update object: System.IndexOutOfRangeException
PostPosted: Wed Aug 12, 2009 10:07 am 
Newbie

Joined: Wed Aug 12, 2009 9:43 am
Posts: 1
Hi,

I am a new NHibernate user and I have a problem, when I want to insert a new object to the database.
This is what I am using:
NHibernate 2.0.1.GA
.NET 3.5 SP1
MySQL 5.1

I can say, that everything works fine with NHibernate, except one thing:
I can not insert/update objects, that have a many-to-one relation. Objects with other relations can be inserted/updated (but the example I created for this question does not contain any other relations than one many-to-one relation).
If there is minimum one many-to-one relation (or more than on) this Exception will be thrown:
"A first chance exception of type 'System.IndexOutOfRangeException' occurred in NHibernate.dll."

Here are the mapping-files (just two tables, called aaa_order and aaa_customer):

Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly ="TestAssembly">
    <class name="TestNamespace.aaa_customer,TestNamespace" table="aaa_customer" lazy="true">
    <id name="ID" column="ID" type="string">
      <generator class="assigned" />
    </id>
    <property type="string" length="255" name="Name" column="`Name`" />

    <bag name ="Orders" table ="TestNamespace.aaa_order" cascade="all-delete-orphan" lazy="false">
      <key column ="`Customer_ID`" />
      <one-to-many class ="TestNamespace.aaa_order"/>
    </bag>   
   
  </class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly ="TestAssembly">
    <class name="TestNamespace.aaa_order,TestNamespace" table="aaa_order" lazy="true">
    <id name="ID" column="ID" type="string">
      <generator class="assigned" />
    </id>
    <property type="string" length="255" name="Name" column="`Name`" />
    <property type="string" length="64" name="CustomerID" column="`Customer_ID`" />

    <many-to-one name ="Customer" class="TestNamespace.aaa_customer" column ="`Customer_ID`" cascade ="all" />
    </class>
</hibernate-mapping>


So I think, the database structure is clear, isn't it (a very simple one to n relation between table Customer and table Order)?

I tested a little bit (ok, not just a little bit...) and I found out, that I can insert new objects of "aaa_order" , if I comment out the many-to-one relation in the maaping-file like this:
Code:
<!--
<many-to-one name ="Customer" class="TestNamespace.aaa_customer" column ="`Customer_ID`" cascade ="all" />
-->


But this is not, what I want.

Can anyone help me, please?

Kind regards,

Stefan


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.