-->
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.  [ 3 posts ] 
Author Message
 Post subject: NHibernate index problem
PostPosted: Wed Nov 22, 2006 6:08 am 
Beginner
Beginner

Joined: Wed Nov 22, 2006 5:59 am
Posts: 29
Location: London
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

1.2.0 Beta 1


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
namespace="BCS.Communications.Data.Tables" assembly="BCS.Communications.Data">
<class name="Customer">
<id name ="CustomerId" column="CustomerId" type="int">
<generator class="native" />
</id>
<property name="CustomerName">
<column name="CustomerName" sql-type="NVARCHAR(MAX)"/>
</property>
<list name="Orders" cascade="all" fetch="join">
<key column="OrderId" foreign-key="fk_customer_order"/>
<index column="idx" type="byte"/>
<one-to-many class="CustomerOrder" />
</list>
</class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
namespace="BCS.Communications.Data.Tables" assembly="BCS.Communications.Data">
<class name="CustomerOrder">
<id name ="OrderId" column="OrderId" type="int">
<generator class="native" />
</id>
<property name="OrderName">
<column name="OrderName" sql-type="NVARCHAR(MAX)"/>
</property>
<many-to-one name="CustomerId" class="Customer" column="CustomerId" foreign-key="fk_customer_order" />
</class>
</hibernate-mapping>


I'm having problems with the index created for using lists in the mapping files. I am using an IList in my entity class for customer orders. The problem is when you add a new customer order the idx index field in the database is set to null. The customerId field in CustomerOrder is set correctly but I can't seem to get the index field to initialize. The code I'm using to test this is below.


Code:
        public void TestRelationship()
        {
            try
            {
                ISession session = NHibernateHelper.GetCurrentSession();
                Customer c = new Customer();
                c.CustomerName = "Test";
                c.AddOrder(new CustomerOrder());
                session.SaveOrUpdateCopy(c);
            }
            catch (Exception e)
            {
            }
        }
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 22, 2006 6:19 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You can't use lists nor maps with <one-to-many> in NHibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 22, 2006 6:31 am 
Beginner
Beginner

Joined: Wed Nov 22, 2006 5:59 am
Posts: 29
Location: London
Someone else who is working on a different project than me has this working with one-to-many though we just can't get it to work in this instance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.