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]