Also, here's some supporting documenation of the problem...
The mapping:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
xmlns="urn:nhibernate-mapping-2.2"
namespace="Core.Domain.Parameter"
assembly="Core"
default-access="field.camelcase-underscore"
default-cascade="save-update">
<!-- Maps the base interface for all Profile parameter types -->
<class name="ProfileParameterDefinition" table="ApplicationProfileDefinitions" discriminator-value="0">
<id name="Id" column="ApplicationProfileDefinitionId" unsaved-value="0" access="nosetter.camelcase-underscore">
<generator class="native" />
</id>
<discriminator column="Type" type="Int32" />
<property name="Name" column="Name" />
<property name="Category" column="Category" />
<property name="Description" column="Description" />
<many-to-one name="Application" column="ApplicationId" class="Core.Domain.Apps.Application" />
</class>
<!-- Maps the integer subclass -->
<subclass name="IntegerProfileParameterDefinition" extends="ProfileParameterDefinition" discriminator-value="5">
<property name="MinValue" column="Minimum" />
<property name="MaxValue" column="Maximum" />
<property name="RestrictToPicklist" column="RestrictToPicklist" />
<bag name="PicklistValues" table="ApplicationProfilePicklist">
<key column="ApplicationProfileDefinitionId" />
<element column="PicklistValue" type="Int64" />
</bag>
</subclass>
<!-- Maps the string subclass -->
<subclass name="StringProfileParameterDefinition" extends="ProfileParameterDefinition" discriminator-value="6">
<property name="MinLength" column="Minimum" />
<property name="MaxLength" column="Maximum" />
<property name="RestrictToPicklist" column="RestrictToPicklist" />
<bag name="PicklistValues" table="ApplicationProfilePicklist" >
<key column="ApplicationProfileDefinitionId" />
<element column="PicklistValue" type="String" />
</bag>
</subclass>
</hibernate-mapping>
This is a segment of the debug logs showing that the mapping was parsed correctly and that the types for the collections were read:
Quote:
NHibernate.Cfg.HbmBinder: 2007-09-18 11:40:47,875 [TestRunnerThread] INFO [(null)] <(null)> - mapping collection: Core.Domain.Apps.Application.ProfileParameterDefinitions -> ApplicationProfileDefinitions
NHibernate.Cfg.CollectionSecondPass: 2007-09-18 11:40:47,890 [TestRunnerThread] DEBUG [(null)] <(null)> - Mapped collection key: ApplicationID, one-to-many: ProfileParameterDefinition
NHibernate.Cfg.CollectionSecondPass: 2007-09-18 11:40:47,890 [TestRunnerThread] DEBUG [(null)] <(null)> - Second pass for collection: Core.Domain.Parameter.IntegerProfileParameterDefinition.PicklistValues
NHibernate.Cfg.CollectionSecondPass: 2007-09-18 11:40:47,906 [TestRunnerThread] DEBUG [(null)] <(null)> - Mapped collection key: ApplicationProfileDefinitionId, element: PicklistValue, type: Int64
NHibernate.Cfg.CollectionSecondPass: 2007-09-18 11:40:47,906 [TestRunnerThread] DEBUG [(null)] <(null)> - Second pass for collection: Core.Domain.Parameter.StringProfileParameterDefinition.PicklistValues
NHibernate.Cfg.CollectionSecondPass: 2007-09-18 11:40:47,906 [TestRunnerThread] DEBUG [(null)] <(null)> - Mapped collection key: ApplicationProfileDefinitionId, element: PicklistValue, type: String
And finally the debug logs of the actual inserts into the database. Note that for the IntegerProfileParameterDefinition a new IDbCommand is built but for the StringProfileParameterDefinition the IDbCommand is re-used.
Quote:
NHibernate.Persister.Collection.ICollectionPersister: 2007-09-18 12:41:51,000 [TestRunnerThread] DEBUG [(null)] <(null)> - Inserting collection: [Core.Domain.Parameter.IntegerProfileParameterDefinition.PicklistValues#41]
NHibernate.Impl.BatcherImpl: 2007-09-18 12:41:51,093 [TestRunnerThread] DEBUG [(null)] <(null)> - Opened new IDbCommand, open IDbCommands: 1
NHibernate.Impl.BatcherImpl: 2007-09-18 12:41:51,109 [TestRunnerThread] DEBUG [(null)] <(null)> - Building an IDbCommand object for the SqlString: INSERT INTO Tests.dbo.ApplicationProfilePicklist (ApplicationProfileDefinitionId, PicklistValue) VALUES (?, ?)
NHibernate.Type.Int32Type: 2007-09-18 12:41:51,125 [TestRunnerThread] DEBUG [(null)] <(null)> - binding '41' to parameter: 0
NHibernate.Type.Int64Type: 2007-09-18 12:41:51,125 [TestRunnerThread] DEBUG [(null)] <(null)> - binding '5' to parameter: 1
NHibernate.SQL: 2007-09-18 12:41:51,125 [TestRunnerThread] DEBUG [(null)] <(null)> - INSERT INTO Tests.dbo.ApplicationProfilePicklist (ApplicationProfileDefinitionId, PicklistValue) VALUES (@p0, @p1); @p0 = '41', @p1 = '5'
NHibernate.Type.Int32Type: 2007-09-18 12:41:51,140 [TestRunnerThread] DEBUG [(null)] <(null)> - binding '41' to parameter: 0
NHibernate.Type.Int64Type: 2007-09-18 12:41:51,140 [TestRunnerThread] DEBUG [(null)] <(null)> - binding '6' to parameter: 1
NHibernate.SQL: 2007-09-18 12:41:51,140 [TestRunnerThread] DEBUG [(null)] <(null)> - INSERT INTO Tests.dbo.ApplicationProfilePicklist (ApplicationProfileDefinitionId, PicklistValue) VALUES (@p0, @p1); @p0 = '41', @p1 = '6'
NHibernate.Type.Int32Type: 2007-09-18 12:41:51,156 [TestRunnerThread] DEBUG [(null)] <(null)> - binding '41' to parameter: 0
NHibernate.Type.Int64Type: 2007-09-18 12:41:51,156 [TestRunnerThread] DEBUG [(null)] <(null)> - binding '7' to parameter: 1
NHibernate.SQL: 2007-09-18 12:41:51,156 [TestRunnerThread] DEBUG [(null)] <(null)> - INSERT INTO Tests.dbo.ApplicationProfilePicklist (ApplicationProfileDefinitionId, PicklistValue) VALUES (@p0, @p1); @p0 = '41', @p1 = '7'
NHibernate.Persister.Collection.ICollectionPersister: 2007-09-18 12:41:51,156 [TestRunnerThread] DEBUG [(null)] <(null)> - done inserting collection: 3 rows inserted
NHibernate.Persister.Collection.ICollectionPersister: 2007-09-18 12:41:51,171 [TestRunnerThread] DEBUG [(null)] <(null)> - Inserting collection: [Core.Domain.Parameter.StringProfileParameterDefinition.PicklistValues#42]
NHibernate.Impl.BatcherImpl: 2007-09-18 12:41:51,187 [TestRunnerThread] DEBUG [(null)] <(null)> - reusing command INSERT INTO Tests.dbo.ApplicationProfilePicklist (ApplicationProfileDefinitionId, PicklistValue) VALUES (@p0, @p1)
NHibernate.Type.Int32Type: 2007-09-18 12:41:51,187 [TestRunnerThread] DEBUG [(null)] <(null)> - binding '42' to parameter: 0
NHibernate.Type.StringType: 2007-09-18 12:41:51,218 [TestRunnerThread] DEBUG [(null)] <(null)> - binding 'orb' to parameter: 1
NHibernate.SQL: 2007-09-18 12:41:51,218 [TestRunnerThread] DEBUG [(null)] <(null)> - INSERT INTO Tests.dbo.ApplicationProfilePicklist (ApplicationProfileDefinitionId, PicklistValue) VALUES (@p0, @p1); @p0 = '42', @p1 = 'orb'
NHibernate.Impl.BatcherImpl: 2007-09-18 12:41:51,265 [TestRunnerThread] DEBUG [(null)] <(null)> - Closed IDbCommand, open IDbCommands: 0
NHibernate.Util.ADOExceptionReporter: 2007-09-18 12:41:51,281 [TestRunnerThread] DEBUG [(null)] <(null)> - could not insert collection: [Core.Domain.Parameter.StringProfileParameterDefinition.PicklistValues#42]
System.FormatException: Failed to convert parameter value from a String to a Int64. ---> System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)