I've been trying to save an order list, but the index value is not being saved in the database. In fact, during a save, the order column is being ignored (I can put an invalid column in there and do not get an error; on load I do get an error in that case however.) Note in the generated sql that the PortOrder column is not in the insert.
The other thing I noticed is that without making this bidirectional, the PortId is not saved in my Device table either. This is true for a bag as well.
Hibernate version:
1.2.1.GA
Mapping documents:
port.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Bosch.RPS.Domain"
assembly="Bosch.RPS.Domain"
default-lazy="false">
<class name="Port" table="Port">
<id name="Id" column="PortId" access="nosetter.pascalcase-m-underscore" type="Int32" unsaved-value="0">
<generator class="identity" />
</id>
<property name="Name" column="Name" type="string" length="50" not-null="true"/>
<property name="m_SIType" column="SIType" access="field" type="string" length="50" not-null="true"/>
<property name="m_StaticIdentifier" access="field" column="StaticIdentifier" type="string" length="50" not-null="true"/>
<property name="m_StaticPosition" access="field" column="StaticPosition" type="Int32" not-null="true"/>
<property name="EnforceParentAreaAssignment" column="EnforceParentAreaAssignment" />
<list name="m_ConnectedDeviceList" access="field" generic="true" cascade="all-delete-orphan" inverse="true">
<key column="PortId" />
<index column="PortOrder" />
<one-to-many class="Device"/>
</list>
<many-to-one unique="true" name="m_ParentDevice" class="Device" column="ParentDeviceId" access="field" />
</class>
</hibernate-mapping>
Device.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Bosch.RPS.Domain"
assembly="Bosch.RPS.Domain"
default-lazy="false">
<class name="Device" table="Device">
<id name="Id" column="DeviceId" access="nosetter.pascalcase-m-underscore" type="Int32" unsaved-value="0">
<generator class="identity" />
</id>
<property name="Name" column="Name" type="string" length="50" not-null="true"/>
<property name="DeviceType" column="DeviceType" type="string" length="50" not-null="true"/>
<property name="SerialNumber" column="SerialNumber" type="string" length="50" />
<property name="m_SIID" access="field" column="SIID" type="string" length="200" />
<property name="m_DeviceLocator" access="field" column="DeviceLocator" type="Int32" />
<many-to-one name="Panel" class="MapSecurityPanel" column="PanelId" cascade="save-update"/>
<many-to-one unique="true" name="ConnectedTo" class="Port" column="PortId" access="nosetter.pascalcase-m-underscore"/>
<many-to-one name="Area" class="Area" column="AreaId" access="nosetter.pascalcase-m-underscore" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
Sql Server 2005 Express
The generated SQL (show_sql=true):
NHibernate: INSERT INTO RPSMap.dbo.Device (Name, DeviceType, SerialNumber, SIID, DeviceLocator, PanelId, PortId, AreaId) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7); select SCOPE_IDENTITY(); @p0 = 'Onboard Connection', @p1 = 'OnboardDDIF', @p2 = '', @p3 = '0.0.Module.21001.001', @p4 = '1', @p5 = '154', @p6 = '681', @p7 = ''
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html