-->
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: When persisting a list, the index column is not being saved
PostPosted: Thu Feb 28, 2008 11:21 pm 
Newbie

Joined: Thu Jan 17, 2008 1:33 pm
Posts: 6
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 29, 2008 6:34 am 
Beginner
Beginner

Joined: Tue Mar 27, 2007 4:54 am
Posts: 47
When using an indexed collection with inverse set to true, the index also need to be mapped and handeled in the "item entity".

Add something like...
<property name="PostOrder" column="PostOrder"/>
...to your Device mapping.

Also, make sure, in code, that index of the post order can be read from within itself. Something like
class Device
{
...
public int PostOrder
{
get { return ConnectedTo.ConnectedDeviceList.IndexOf(this);}
set { //do nada}
}
...
}


Top
 Profile  
 
 Post subject: NH 2.0?
PostPosted: Tue Jul 22, 2008 6:46 pm 
Newbie

Joined: Wed Jul 16, 2008 4:42 pm
Posts: 2
Is there an nicer way in NHibernate 2.0?
Finding an appropriate documentation for the Beta isn't that easy, unfortunately.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 23, 2008 5:15 am 
Beginner
Beginner

Joined: Tue Mar 27, 2007 4:54 am
Posts: 47
I don't think so.

I'm using the trunk and I still do it this way, where I need a bidirectional ref with a index column.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2008 7:08 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
I have a working example of bidirectional lists here.

_________________
Gonzalo Díaz


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.