-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem using idbag
PostPosted: Mon Nov 21, 2005 1:16 pm 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
I'm trying to use an idbag to contain a many-to-any list of objects.

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="Framework.Core.Entities" assembly="Framework.Core" default-access="field.camelcase">
   
   <class name="Document" table="Documents" lazy="true">
      
      <id name="Id" column="DocumentID" unsaved-value="0" >
         <generator class="native" />
      </id>
      
      <version name="Version" column="Version"  />
      
      <property name="Description" column="Description" length="255" />
             
          <idbag name="Associations" table="DocumentAssociations" lazy="true" cascade="all">
          
             <collection-id column="AssociationID" type="Int32">
                <generator class="native"/>
             </collection-id>
          
         <key column="AssociatedDocumentID" />
         
         <many-to-any id-type="Int32" meta-type="string">
         
            <meta-value value="Framework.Core.Entities.Customer" class="Customer"/>
            <meta-value value="Framework.Core.Entities.User" class="User"/>
            <meta-value value="Framework.Core.Entities.Contractor" class="Contractor"/>
            
            <column name="entityType"/>
            <column name="entityId"/>
            
         </many-to-any>

      </idbag>
   
   
   </class>
</hibernate-mapping>



Whenever I try to add an item to the collection I get the following exception:

Code:
[2192] NHibernate.Util.ADOExceptionReporter: 2005-11-21 18:00:17,760
[624] DEBUG [(null)] <(null)> - could not insert collection: [Framework.Core.Entities.Document.Associations#182527]
[2192] System.InvalidCastException: Object must implement IConvertible.
[2192]    at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
[2192]    at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
[2192]    at NHibernate.Impl.BatcherImpl.ExecuteNonQuery(IDbCommand cmd)
[2192]    at NHibernate.Impl.NonBatchingBatcher.AddToBatch(Int32 expectedRowCount)
[2192]    at NHibernate.Collection.AbstractCollectionPersister.Recreate(PersistentCollection collection, Object id, ISessionImplementor session)
[2192] NHibernate.Util.ADOExceptionReporter: 2005-11-21 18:00:17,760 [624] WARN  [(null)] <(null)> - System.InvalidCastException: Object must implement IConvertible.
[2192]    at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
[2192]    at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
[2192]    at NHibernate.Impl.BatcherImpl.ExecuteNonQuery(IDbCommand cmd)
[2192]    at NHibernate.Impl.NonBatchingBatcher.AddToBatch(Int32 expectedRowCount)
[2192]    at NHibernate.Collection.AbstractCollectionPersister.Recreate(PersistentCollection collection, Object id, ISessionImplementor session)
[2192] NHibernate.Util.ADOExceptionReporter: 2005-11-21 18:00:17,760 [624] ERROR [(null)] <(null)> - Object must implement IConvertible.
[2192] NHibernate.ADOException: 2005-11-21 18:00:17,760 [624] ERROR [(null)] <(null)> - could not insert collection: [Framework.Core.Entities.Document.Associations#182527]
[2192] System.InvalidCastException: Object must implement IConvertible.
[2192]    at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
[2192]    at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
[2192]    at NHibernate.Impl.BatcherImpl.ExecuteNonQuery(IDbCommand cmd)
[2192]    at NHibernate.Impl.NonBatchingBatcher.AddToBatch(Int32 expectedRowCount)
[2192]    at NHibernate.Collection.AbstractCollectionPersister.Recreate(PersistentCollection collection, Object id, ISessionImplementor session)
[2192] NHibernate.Impl.SessionImpl: 2005-11-21 18:00:17,760 [624] ERROR [(null)] <(null)> - could not synchronize database state with session
[2192] NHibernate.ADOException: could not insert collection: [Framework.Core.Entities.Document.Associations#182527] ---> System.InvalidCastException: Object must implement IConvertible.
[2192]    at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
[2192]    at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
[2192]    at NHibernate.Impl.BatcherImpl.ExecuteNonQuery(IDbCommand cmd)
[2192]    at NHibernate.Impl.NonBatchingBatcher.AddToBatch(Int32 expectedRowCount)
[2192]    at NHibernate.Collection.AbstractCollectionPersister.Recreate(PersistentCollection collection, Object id, ISessionImplementor session)
[2192]    --- End of inner exception stack trace ---
[2192]    at NHibernate.Collection.AbstractCollectionPersister.Recreate(PersistentCollection collection, Object id, ISessionImplementor session)
[2192]    at NHibernate.Impl.ScheduledCollectionRecreate.Execute()
[2192]    at NHibernate.Impl.SessionImpl.Execute(IExecutable executable)
[2192]    at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
[2192]    at NHibernate.Impl.SessionImpl.Execute()
[2192] NHibernate.Transaction.AdoTransaction: 2005-11-21 18:00:17,760 [624] DEBUG [(null)] <(null)> - rollback
[2192] NHibernate.Transaction.AdoTransaction: 2005-11-21 18:00:17,760 [624] DEBUG [(null)] <(null)> - running AdoTransaction.Dispose()
[2192] NHibernate.Impl.SessionImpl: 2005-11-21 18:00:17,760 [624] DEBUG [(null)] <(null)> - transaction completion


And here's the debug output specifying the SQL statement and the values bound to the parameters:

Code:
[2192] NHibernate.Impl.BatcherImpl: 2005-11-21 18:00:17,760 [624] DEBUG [(null)] <(null)> - Building an IDbCommand object for the SqlString: INSERT INTO DocumentAssociations (AssociatedDocumentID, AssociationID, entityType, entityId) VALUES (:AssociatedDocumentID, :AssociationID, :entityType, :entityId)
[2192] NHibernate.Type.Int32Type: 2005-11-21 18:00:17,760 [624] DEBUG [(null)] <(null)> - binding '182527' to parameter: 0
[2192] NHibernate.Type.StringType: 2005-11-21 18:00:17,760 [624] DEBUG [(null)] <(null)> - binding 'Framework.Core.Entities.Customer' to parameter: 2
[2192] NHibernate.Type.Int32Type: 2005-11-21 18:00:17,760 [624] DEBUG [(null)] <(null)> - binding '1' to parameter: 3
[2192] NHibernate.Type.Int32Type: 2005-11-21 18:00:17,760 [624] DEBUG [(null)] <(null)> - binding 'System.Object' to parameter: 1
[2192] NHibernate.Impl.BatcherImpl: 2005-11-21 18:00:17,760 [624] DEBUG [(null)] <(null)> - Closed IDbCommand, open IDbCommands :0


I'm completely stumped - is anyone else using idbags with an identity column successfully? Is this a bug?

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 2:09 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Looks like it's this one: NH-364.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 2:55 pm 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
D'oh....

Ah well, back to a <bag> for me...I can change to an <idbag> later to improve performance since the db table has the identity column anyway!

Ta,

Symon.


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