|
I'm using NHibernate, which is a .NET port from Java Hibernate 2.1.7, and came across this issue. Hope someone help me out. Thanks a lot.
I have a bidirectional many-to-many mapping with index column. When I try to delete any child which is not the last one in the collection, deletion fails.
Mapping file at parent site:
[ol] [/ol]复制代码
Mapping file at child site:
[ol] [/ol]复制代码
Table Schema:
[ol]CREATE TABLE [dbo].[EBS_C_Category_Product] ( [CategoryId] [uniqueidentifier] NOT NULL , [ProductId] [uniqueidentifier] NOT NULL , [DisplayOrder] [int] NOT NULL ) [/ol]复制代码
Code used to delete a child:
[ol] objCategory.Products.Remove(objProduct); objProduct.Categories.Remove(objCategory); SessionManager.GetSession().SaveOrUpdate(objCategory); [/ol]复制代码
Error message
[ol]Violation of PRIMARY KEY constraint 'PK_EBS_C_Category_Product'. Cannot insert duplicate key in object 'EBS_C_Category_Product'. The statement has been terminated. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK_EBS_C_Category_Product'. Cannot insert duplicate key in object 'EBS_C_Category_Product'. The statement has been terminated. Source Error: Line 173: CheckReaders(); Line 174: Prepare(cmd); Line 175: return cmd.ExecuteNonQuery(); Line 176: } Line 177: Source File: C:\temp\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Impl\BatcherImpl.cs Line: 175 Stack Trace: [SqlException (0x80131904): Violation of PRIMARY KEY constraint 'PK_EBS_C_Category_Product'. Cannot insert duplicate key in object 'EBS_C_Category_Product'. The statement has been terminated.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857386 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734998 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +149 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +886 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +415 System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +135 NHibernate.Impl.BatcherImpl.ExecuteNonQuery(IDbCommand cmd) in C:\temp\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Impl\BatcherImpl.cs:175 NHibernate.Impl.NonBatchingBatcher.AddToBatch(IExpectation expectation) in C:\temp\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Impl\NonBatchingBatcher.cs:36 NHibernate.Persister.Collection.BasicCollectionPersister.DoUpdateRows(Object id, IPersistentCollection collection, ISessionImplementor session) in C:\temp\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Persister\Collection\BasicCollectionPersister.cs:222 [ADOException: could not update collection rows: [EBSimple.Commerce.DomainModel.Category.Products#2877d2b2-e890-48dd-8908-98ac0183c17e]] EBSimple.Core.NHibernateSessionManager.CommitTransaction() in C:\DNNDevEnvironment\DesktopModules\EBSimpleCommerce\Core\NHibernateSessionManager.cs:131 EBSimple.Commerce.HttpModules.NHibernateSessionModule.CommitAndCloseSession(Object sender, EventArgs e) in C:\DNNDevEnvironment\DesktopModules\EBSimpleCommerce\HttpModules\NHibernateSessionModule.cs:43 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64 -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210 [/ol]复制代码
Frank
--------------------------------------------------------------------------------
[ 本帖最后由 Frankman 于 2007-1-15 10:50 编辑 ] |
上一篇:招聘full time会计,Sydney city,适合需要第一份会计工作的人(已招到,谢谢)下一篇:我被四大Phone Interview
|