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.  [ 2 posts ] 
Author Message
 Post subject: List mapping remove problem
PostPosted: Thu Aug 03, 2006 2:37 pm 
Newbie

Joined: Mon Jan 16, 2006 12:59 pm
Posts: 5
Location: Zagreb, Croatia
Hibernate version: 1.2.0.Alpha1

Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" default-lazy="false" >
   <class name="Bss.AppFramework.Common.Catalog.Admin.CatalogMenuEntity, Bss.AppFramework.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c38a8b11dd11713" table="Menu">
      <id name="Id" column="MenuId" type="System.Int32" unsaved-value="-1" access="nosetter.camelcase-underscore">
         <generator class="native" />
      </id>

      <version name="Version" unsaved-value="undefined"/>

      <property name="ModifiedTime"  />
      <property name="CreatedTime"  />
      <property name="CreatedUser"   />
      <property name="ModifiedUser"  />
      
      <property name="Caption"   />

      <property name="NestingLevel"  />
      <property name="CustomData"   />
      
      <many-to-one name="TargetWindow" class="Bss.AppFramework.Common.Catalog.Admin.CatalogWindowEntity, Bss.AppFramework.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c38a8b11dd11713" 
            column="TargetWindowId"  unique="true" />      
      

      <bag name="Permissions" cascade="all-delete-orphan" access="nosetter.camelcase-underscore"
         lazy="true" inverse="true" >
         <key column="MenuId" />


         <one-to-many class="Bss.AppFramework.Common.Catalog.Admin.CatalogMenuPermissionEntity, Bss.AppFramework.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c38a8b11dd11713"   />
      </bag>
      

   </class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping default-lazy="false" xmlns="urn:nhibernate-mapping-2.0">
  <class name="Bss.AppFramework.Common.Catalog.Admin.CatalogApplicationEntity, Bss.AppFramework.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c38a8b11dd11713" table="Application">
    <id name="Id" column="ApplicationId" type="System.Int32" unsaved-value="-1" access="nosetter.camelcase-underscore">
      <generator class="native" />
    </id>
    <version name="Version" unsaved-value="undefined" />
    <property name="CreatedUser" column="CreatedUser" access="field.camelcase-underscore" />
    <property name="CreatedTime" column="CreatedTime" access="field.camelcase-underscore" />
    <property name="ModifiedUser" column="ModifiedUser" access="field.camelcase-underscore" />
    <property name="ModifiedTime" column="ModifiedTime" access="field.camelcase-underscore" />
    <property name="Startup" access="field.camelcase-underscore" column="Startup" type="System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" />
    <property name="License" access="field.camelcase-underscore" column="License" type="System.String" />
    <property name="Name" access="field.camelcase-underscore" column="Name" type="System.String" />
    <property name="PasswordExpirationPeriod" access="field.camelcase-underscore" column="PasswordExpirationPeriod" type="System.Int32" />
    <property name="UserSessionExpirationPeriod" access="field.camelcase-underscore" column="UserSessionExpirationPeriod" type="System.Int32" />
   
    <list name="Menu" cascade="all-delete-orphan" access="field.camelcase-underscore" lazy="true" inverse="false" >     
      <key column="ApplicationId" />
      <index column="`Index`" />         
      <one-to-many class="Bss.AppFramework.Common.Catalog.Admin.CatalogMenuEntity, Bss.AppFramework.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c38a8b11dd11713" />
    </list>
   
    <bag name="Roles" cascade="all-delete-orphan" access="field.camelcase-underscore" lazy="true" inverse="true">
      <key column="ApplicationId" />
      <one-to-many class="Bss.AppFramework.Common.Catalog.Admin.CatalogRoleEntity, Bss.AppFramework.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c38a8b11dd11713" />
    </bag>
  </class>
</hibernate-mapping>


The code:
Code:
        ISession s = PersistenceScope.CurrentFactory.OpenSession();

        CatalogApplicationEntity app = s.Get<CatalogApplicationEntity>(99);

        app.Menu.RemoveAt(Int32.Parse(TextBox3.Text));

        s.Flush();
        s.Close();


Full stack trace of any exception that occurs:
Code:
NHibernate.ADOException was unhandled by user code
  Message="could not delete collection rows: [Bss.AppFramework.Common.Catalog.Admin.CatalogApplicationEntity.Menu#99]"
  Source="NHibernate"
  StackTrace:
       at NHibernate.Persister.Collection.AbstractCollectionPersister.DeleteRows(IPersistentCollection collection, Object id, ISessionImplementor session) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Persister\Collection\AbstractCollectionPersister.cs:line 791
       at NHibernate.Impl.ScheduledCollectionUpdate.Execute() in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Impl\ScheduledCollectionUpdate.cs:line 75
       at NHibernate.Impl.SessionImpl.Execute(IExecutable executable) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Impl\SessionImpl.cs:line 3163
       at NHibernate.Impl.SessionImpl.ExecuteAll(IList list) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Impl\SessionImpl.cs:line 3142
       at NHibernate.Impl.SessionImpl.Execute() in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Impl\SessionImpl.cs:line 3094
       at NHibernate.Impl.SessionImpl.Flush() in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Impl\SessionImpl.cs:line 2930
       at _Default.Button3_Click1(Object sender, EventArgs e) in d:\Projects\AppFramework\trunk\testing\CatalogWeb\Default.aspx.cs:line 644
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


Name and version of the database you are using:
MSSQL 2005

Debug level Hibernate log excerpt:
Code:
2006-08-03 20:16:29,040 [5248] DEBUG NHibernate.Util.ADOExceptionReporter [(null)] <(null)> - could not delete collection rows: [Bss.AppFramework.Common.Catalog.Admin.CatalogApplicationEntity.Menu#99]
System.ArgumentException: There is a problem with your mappings.  You are probably trying to map a System.ValueType to a <class> which NHibernate does not allow or you are incorrectly using the IDictionary that is mapped to a <set>. 

A ValueType (System.Int32) can not be used with IdentityKey.  The thread at google has a good description about what happens with boxing and unboxing ValueTypes and why they can not be used as an IdentityKey: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=bds2rm%24ruc%241%40charly.heeg.de&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26q%3DSystem.Runtime.CompilerServices.RuntimeHelpers.GetHashCode%26sa%3DN%26tab%3Dwg
Parameter name: key
   at NHibernate.Util.IdentityMap.VerifyValidKey(Object obj) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Util\IdentityMap.cs:line 252
   at NHibernate.Util.IdentityMap.get_Item(Object key) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Util\IdentityMap.cs:line 196
   at NHibernate.Impl.SessionImpl.GetEntry(Object obj) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Impl\SessionImpl.cs:line 662
   at NHibernate.Impl.SessionImpl.GetEntityIdentifierIfNotUnsaved(Object obj) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Impl\SessionImpl.cs:line 3599
   at NHibernate.Type.EntityType.GetIdentifier(Object value, ISessionImplementor session) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Type\EntityType.cs:line 60
   at NHibernate.Type.ManyToOneType.NullSafeSet(IDbCommand cmd, Object value, Int32 index, ISessionImplementor session) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Type\ManyToOneType.cs:line 49
   at NHibernate.Persister.Collection.AbstractCollectionPersister.WriteElementToWhere(IDbCommand st, Object elt, Int32 i, ISessionImplementor session) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Persister\Collection\AbstractCollectionPersister.cs:line 455
   at NHibernate.Persister.Collection.AbstractCollectionPersister.DeleteRows(IPersistentCollection collection, Object id, ISessionImplementor session) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Persister\Collection\AbstractCollectionPersister.cs:line 768
2006-08-03 20:16:29,056 [5248] WARN  NHibernate.Util.ADOExceptionReporter [(null)] <(null)> - System.ArgumentException: There is a problem with your mappings.  You are probably trying to map a System.ValueType to a <class> which NHibernate does not allow or you are incorrectly using the IDictionary that is mapped to a <set>. 

A ValueType (System.Int32) can not be used with IdentityKey.  The thread at google has a good description about what happens with boxing and unboxing ValueTypes and why they can not be used as an IdentityKey: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=bds2rm%24ruc%241%40charly.heeg.de&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26q%3DSystem.Runtime.CompilerServices.RuntimeHelpers.GetHashCode%26sa%3DN%26tab%3Dwg
Parameter name: key
   at NHibernate.Util.IdentityMap.VerifyValidKey(Object obj) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Util\IdentityMap.cs:line 252
   at NHibernate.Util.IdentityMap.get_Item(Object key) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Util\IdentityMap.cs:line 196
   at NHibernate.Impl.SessionImpl.GetEntry(Object obj) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Impl\SessionImpl.cs:line 662
   at NHibernate.Impl.SessionImpl.GetEntityIdentifierIfNotUnsaved(Object obj) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Impl\SessionImpl.cs:line 3599
   at NHibernate.Type.EntityType.GetIdentifier(Object value, ISessionImplementor session) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Type\EntityType.cs:line 60
   at NHibernate.Type.ManyToOneType.NullSafeSet(IDbCommand cmd, Object value, Int32 index, ISessionImplementor session) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Type\ManyToOneType.cs:line 49
   at NHibernate.Persister.Collection.AbstractCollectionPersister.WriteElementToWhere(IDbCommand st, Object elt, Int32 i, ISessionImplementor session) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Persister\Collection\AbstractCollectionPersister.cs:line 455
   at NHibernate.Persister.Collection.AbstractCollectionPersister.DeleteRows(IPersistentCollection collection, Object id, ISessionImplementor session) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Persister\Collection\AbstractCollectionPersister.cs:line 768
2006-08-03 20:16:29,056 [5248] ERROR NHibernate.Util.ADOExceptionReporter [(null)] <(null)> - There is a problem with your mappings.  You are probably trying to map a System.ValueType to a <class> which NHibernate does not allow or you are incorrectly using the IDictionary that is mapped to a <set>. 

A ValueType (System.Int32) can not be used with IdentityKey.  The thread at google has a good description about what happens with boxing and unboxing ValueTypes and why they can not be used as an IdentityKey: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=bds2rm%24ruc%241%40charly.heeg.de&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26q%3DSystem.Runtime.CompilerServices.RuntimeHelpers.GetHashCode%26sa%3DN%26tab%3Dwg
Parameter name: key
2006-08-03 20:16:29,072 [5248] ERROR NHibernate.Impl.SessionImpl [(null)] <(null)> - could not synchronize database state with session
NHibernate.ADOException: could not delete collection rows: [Bss.AppFramework.Common.Catalog.Admin.CatalogApplicationEntity.Menu#99] ---> System.ArgumentException: There is a problem with your mappings.  You are probably trying to map a System.ValueType to a <class> which NHibernate does not allow or you are incorrectly using the IDictionary that is mapped to a <set>. 

A ValueType (System.Int32) can not be used with IdentityKey.  The thread at google has a good description about what happens with boxing and unboxing ValueTypes and why they can not be used as an IdentityKey: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=bds2rm%24ruc%241%40charly.heeg.de&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26q%3DSystem.Runtime.CompilerServices.RuntimeHelpers.GetHashCode%26sa%3DN%26tab%3Dwg
Parameter name: key
   at NHibernate.Util.IdentityMap.VerifyValidKey(Object obj) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Util\IdentityMap.cs:line 252
   at NHibernate.Util.IdentityMap.get_Item(Object key) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Util\IdentityMap.cs:line 196
   at NHibernate.Impl.SessionImpl.GetEntry(Object obj) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Impl\SessionImpl.cs:line 662
   at NHibernate.Impl.SessionImpl.GetEntityIdentifierIfNotUnsaved(Object obj) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Impl\SessionImpl.cs:line 3599
   at NHibernate.Type.EntityType.GetIdentifier(Object value, ISessionImplementor session) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Type\EntityType.cs:line 60
   at NHibernate.Type.ManyToOneType.NullSafeSet(IDbCommand cmd, Object value, Int32 index, ISessionImplementor session) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Type\ManyToOneType.cs:line 49
   at NHibernate.Persister.Collection.AbstractCollectionPersister.WriteElementToWhere(IDbCommand st, Object elt, Int32 i, ISessionImplementor session) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Persister\Collection\AbstractCollectionPersister.cs:line 455
   at NHibernate.Persister.Collection.AbstractCollectionPersister.DeleteRows(IPersistentCollection collection, Object id, ISessionImplementor session) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Persister\Collection\AbstractCollectionPersister.cs:line 768
   --- End of inner exception stack trace ---
   at NHibernate.Persister.Collection.AbstractCollectionPersister.DeleteRows(IPersistentCollection collection, Object id, ISessionImplementor session) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Persister\Collection\AbstractCollectionPersister.cs:line 791
   at NHibernate.Impl.ScheduledCollectionUpdate.Execute() in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Impl\ScheduledCollectionUpdate.cs:line 75
   at NHibernate.Impl.SessionImpl.Execute(IExecutable executable) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Impl\SessionImpl.cs:line 3163
   at NHibernate.Impl.SessionImpl.ExecuteAll(IList list) in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Impl\SessionImpl.cs:line 3142
   at NHibernate.Impl.SessionImpl.Execute() in D:\Projects\AppFramework\trunk\NHibernate 1.2\src\NHibernate\Impl\SessionImpl.cs:line 3087



Adding menu items to the Menu collection of the CatalogApplicationEntity class works fine, but when I try to use Menu.RemoveAt that exception is thrown.

What am I doing wrong?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 08, 2006 4:54 am 
Newbie

Joined: Mon Jan 16, 2006 12:59 pm
Posts: 5
Location: Zagreb, Croatia
Apparently the problem is in the following code in the DeleteRows method in the AbstractCollectionPersister.cs file:

Code:
bool deleteByIndex = !IsOneToMany && hasIndex /* TODO H3: && !indexContainsFormula*/;


If I change this so that deleteByIndex=true in my case everything seems to be working fine. Why shouldn't the items be deleted by the index if it is a one-to-many mapping ??


Is this a bug?[/code]


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