-->
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: update is not incrementing version
PostPosted: Mon Jun 11, 2007 12:14 pm 
Newbie

Joined: Mon Oct 17, 2005 8:54 pm
Posts: 1
i have a one to many and i'm trying to delete the parent + children, however the database (not mine but i have to write to it anyway) has update triggers that insert rows into history tables that have a PK on th entity id + the version column of the entity. When I modify the collection NH is updating the entity before deleting it but it is not incrementing the version causing the trigger to error

The NH logs detect the collection property is dirty which is why I figure it is trying to save my entity (although the entity is deleted so I don't think it should be trying to save it)

My entity is using <version>.

Mappings:

Code:
<hibernate-mapping  auto-import="true" default-lazy="false" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.2">
  <class name=WebUser, Web" table="WebUser">
    <id name="WebUserID" access="property" column="WebUserID" type="Int32" unsaved-value="0">
      <generator class="SerialIdentifierGenerator, Web">
      </generator>
    </id>
    <version name="Version" access="field.camelcase-underscore" column="Version" type="Int32" />
    <property name="ModifyDate" access="property" type="System.DateTime">
      <column name="ModifyDate"/>
    </property>
    <property name="UserID" access="property" type="Int32">
      <column name="UserID"/>
    </property>
    <property name="UserName" access="property" type="String">
      <column name="UserName"/>
    </property>
    <property name="Password" access="property" type="String">
      <column name="Password"/>
    </property>
    <property name="FirstName" access="property" type="String">
      <column name="FirstName"/>
    </property>
    <property name="LastName" access="property" type="String">
      <column name="LastName"/>
    </property>
    <property name="EmailAddress" access="property" type="String">
      <column name="EmailAddress"/>
    </property>
    <property name="SecurityFlags" access="property" type="Int32">
      <column name="SecurityFlags"/>
    </property>
    <property name="LastLogin" access="property" type="System.DateTime">
      <column name="LastLogin"/>
    </property>
    <property name="PasswordHint" access="property" type="String">
      <column name="PasswordHint"/>
    </property>
    <property name="SecureQuestion1" access="property" type="String">
      <column name="SecureQuestion1"/>
    </property>
    <property name="SecureAnswer1" access="property" type="String">
      <column name="SecureAnswer1"/>
    </property>
    <property name="SecureQuestion2" access="property" type="String">
      <column name="SecureQuestion2"/>
    </property>
    <property name="SecureAnswer2" access="property" type="String">
      <column name="SecureAnswer2"/>
    </property>
    <property name="CreationTime" access="property" type="System.DateTime">
      <column name="CreationTime"/>
    </property>
    <bag name="WebUserAccounts" access="nosetter.camelcase-underscore" table="WebUserAccount" lazy="false" inverse="true" cascade="save-update">
      <key column="WebUserID" />
      <one-to-many class="WebUserAccount, Web" />
    </bag>
  </class>
</hibernate-mapping>

<hibernate-mapping  auto-import="true" default-lazy="false" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.2">
  <class name="WebUserAccount, Web" table="WebUserAccount">
    <id name="WebUserAccountID" access="property" column="WebUserAccountID" type="Int32" unsaved-value="0">
      <generator class="SerialIdentifierGenerator, Web">
      </generator>
    </id>
    <version name="Version" access="field.camelcase-underscore" column="Version" type="Int32" />
    <property name="ModifyDate" access="property" type="System.DateTime">
      <column name="ModifyDate"/>
    </property>
    <property name="UserID" access="property" type="Int32">
      <column name="UserID"/>
    </property>
    <property name="SecurityFlags" access="property" type="Int32">
      <column name="SecurityFlags"/>
    </property>
    <property name="AccountID" access="property" type="Int32">
      <column name="AccountID"/>
    </property>
    <many-to-one name="WebUser" access="property" class="WebUser, Web" column="WebUserID" />
  </class>
</hibernate-mapping>


Code:
foreach (WebUser toDelete in WebUser.FindAll())
                  {
                     toDelete.WebUserAccounts.Clear();
                     toDelete.Delete();
                  }


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.