Hi everybody,
I think I have a problem with table-per-class hierarchy mapping model.
Suppose there's a DocumentLine as a base class for ItemLine. I want that both of them are mapped to exactly 1 (one) table on the database. Table-per-class hierarchy mapping model is what I have in mind according to this inheritance type. I use DocumentLineType column as the discriminator column.
The problem occurs since I want the discriminator use the same column as the DocumentLineType property. I want it that way because I also have to maintain the DocumentLineType at the application (as a property), not just as an internal NHibernate mapping stuff (as a discriminator).
Is there any way I can achieve this?
CMIIW and thanks before.
Microsoft SQL Server 2005 SP2
NHibernate Version: 1.2.0 GA
Mapping Documents
<class name="Max.Finance.NHibernate.DocumentLine, Max.Finance.NHibernate" table="DocumentLine" dynamic-update="true" discriminator-value="-1">
<id name="Id" column="DocumentLineId" type="System.Int64" access="nosetter.camelcase">
<generator class="identity">
</generator>
</id>
<discriminator column="DocumentLineTypeId" type="System.Int64" not-null="true" />
<version name="RowVersion" column="RowVersion" type="System.Int64" access="nosetter.camelcase" />
<property name="RowGuid" column="RowGuid" type="System.Guid" access="nosetter.camelcase" not-null="true" insert="false" update="false" generated="insert" />
<property name="DocumentLineType" column="DocumentLineTypeId" type="Max.Finance.NHibernate.DocumentLineType, Max.Finance.NHibernate" access="property" not-null="true" insert="true" update="false" />
<many-to-one name="Document" column="DocumentId" class="Max.Finance.NHibernate.Document, Max.Finance.NHibernate" access="property" not-null="true" />
<property name="FinancialDateTime" column="FinancialDateTime" type="System.DateTime" access="property" not-null="true" insert="true" update="false" />
<property name="LineOrder" column="LineOrder" type="System.Int32" access="property" not-null="true" />
<property name="SubAmount" column="SubAmount" type="System.Decimal" access="nosetter.camelcase" not-null="true" />
<property name="Amount" column="Amount" type="System.Decimal" access="nosetter.camelcase" not-null="true" />
</class>
<subclass name="Max.Finance.NHibernate.ItemLine, Max.Finance.NHibernate" extends="Max.Finance.NHibernate.DocumentLine, Max.Finance.NHibernate" dynamic-update="true" discriminator-value="4">
<many-to-one name="Item" column="ItemAccountId" class="Max.Finance.NHibernate.Item, Max.Finance.NHibernate" access="property" not-null="true" />
<property name="UnitPrice" column="UnitPrice" type="System.Decimal" access="property" not-null="true" />
<property name="Quantity" column="Quantity" type="System.Double" access="property" not-null="true" />
<property name="DiscountAmount" column="DiscountAmount" type="System.Decimal" access="property" not-null="true" />
</subclass>
Exception and Stack Trace
NHibernate.ADOException was unhandled by user code
Message="could not insert: [Max.Finance.NHibernate.ItemLine][SQL: INSERT INTO DocumentLine (ItemAccountId, UnitPrice, Quantity, DiscountAmount, RowVersion, CreationDateTime, ModificationDateTime, DeletionDateTime, DocumentLineTypeId, DocumentId, FinancialDateTime, LineOrder, SubAmount, Amount, DocumentLineTypeId) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 4)]"
Source="NHibernate"
StackTrace:
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Boolean[] notNull, SqlCommandInfo sql, Object obj, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Object obj, ISessionImplementor session)
at NHibernate.Impl.ScheduledIdentityInsertion.Execute()
at NHibernate.Impl.SessionImpl.Execute(IExecutable executable)
at NHibernate.Impl.SessionImpl.DoSave(Object theObj, EntityKey key, IEntityPersister persister, Boolean replicate, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)
at NHibernate.Impl.SessionImpl.DoSave(Object obj, Object id, IEntityPersister persister, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)
at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)
at NHibernate.Impl.SessionImpl.Save(Object obj)
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
at Castle.Facilities.NHibernateIntegration.SessionDelegate.SaveOrUpdate(Object obj)
at Max.System.Data.NHibernate.EntityRepository`1.Save(T entity) in D:\Users\mahara\Projects\Personal\Software\Max.Finance\Private\1.0\Source Codes\Max.System.Data.NHibernate\EntityRepository.Generic.cs:line 382
at Max.System.Data.NHibernate.EntityValidation`1.Save(T entity) in D:\Users\mahara\Projects\Personal\Software\Max.Finance\Private\1.0\Source Codes\Max.System.Data.NHibernate\EntityValidation.Generic.cs:line 389
at Max.System.Data.NHibernate.EntityDataAccess`1.Save(T entity) in D:\Users\mahara\Projects\Personal\Software\Max.Finance\Private\1.0\Source Codes\Max.System.Data.NHibernate\EntityDataAccess.Generic.cs:line 304
at Max.Finance.NHibernate.SalesInvoiceDataManagement.Update(SalesInvoice salesInvoice) in D:\Users\mahara\Projects\Personal\Software\Max.Finance\Private\1.0\Source Codes\Max.Finance.NHibernate\Document\SalesInvoiceDataManagement.cs:line 121
at Max.Finance.NHibernate.SalesInvoiceManagement.ProcessForAddition(SalesInvoice salesInvoice) in D:\Users\mahara\Projects\Personal\Software\Max.Finance\Private\1.0\Source Codes\Max.Finance.NHibernate\Document\SalesInvoiceManagement.cs:line 30
at ISalesInvoiceManagementProxy1683386f56b148b2936d5dbf6a53991e.InvocationProcessForAddition_2.InvokeMethodOnTarget()
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Facilities.AutomaticTransactionManagement.TransactionInterceptor.Intercept(IInvocation invocation)
Inner Exception and Stack Trace
"Column name 'DocumentLineTypeId' appears more than once in the result column list."
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at NHibernate.Impl.BatcherImpl.ExecuteReader(IDbCommand cmd)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Boolean[] notNull, SqlCommandInfo sql, Object obj, ISessionImplementor session)
_________________ Regards,
Maximilian Haru Raditya
|