我有两个从同一个表中读取的连接子类,其中一个可空字段作为鉴别器。我已经能够使用这样的子选择读取两个实体:
<joined-subclass name="EntityA"
table="t_entity"
subselect="SELECT * FROM t_entity WHERE t_entity.discriminator is not null">
<key column="t_uid"></key>
<!-- more mapping -->
</joined-subclass>
<joined-subclass name="EntityB"
table="t_entity"
subselect="SELECT * FROM t_entity WHERE t_entity.discriminator is null">
<key column="t_uid"></key>
<!-- more mapping -->
</joined-subclass>
一切都很好,但是当我尝试删除两个实体之一时,出现语法错误:
NHibernate.Exceptions.GenericADOException was unhandled
HResult=-2146232832
Message=could not delete: [EntityA#27]
[SQL: DELETE FROM ( SELECT *
FROM t_entity
WHERE t_entity.discriminator is not null ) WHERE t_uid = ?]
Source=NHibernate
关于如何通过可为空字段区分同一个表中的实体有更好的想法吗?
这里是堆栈跟踪:
at NHibernate.Persister.Entity.AbstractEntityPersister.Delete(Object id, Object version, Int32 j, Object obj, SqlCommandInfo sql, ISessionImplementor session, Object[] loadedState)
at NHibernate.Persister.Entity.AbstractEntityPersister.Delete(Object id, Object version, Object obj, ISessionImplementor session)
at NHibernate.Action.EntityDeleteAction.Execute()
at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
at NHibernate.Engine.ActionQueue.ExecuteActions()
at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
at NHibernate.Impl.SessionImpl.Flush()
at NHibernate.Transaction.AdoTransaction.Commit()
at Nephila.Toolkit.Data.Implementations.Transaction.Commit() in C:\Projects\Git\nephilaapiTFS\Toolkit\Nephila.Toolkit.Data.Implementations\Transaction.cs:line 48
at Nephila.Dashboard.ServiceLayer.WidgetRegistrationService.UnregisterWidget(Widget widget) in C:\Projects\Git\nephilaapiTFS\Dashboard\Nephila.Dashboard.ServiceLayer\WidgetRegistrationService.cs:line 206
at Nephila.Dashboard.WidgetRegistrationConsole.Instance.UnregisterWidget(String widgetUrlName) in C:\Projects\Git\nephilaapiTFS\Nephila.Dashboard.WidgetRegistrationConsole\Program.cs:line 254
at Nephila.Dashboard.WidgetRegistrationConsole.Instance.Display(String[] args) in C:\Projects\Git\nephilaapiTFS\Nephila.Dashboard.WidgetRegistrationConsole\Program.cs:line 97
at Nephila.Dashboard.WidgetRegistrationConsole.Program.Main(String[] args) in C:\Projects\Git\nephilaapiTFS\Nephila.Dashboard.WidgetRegistrationConsole\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Data.SqlClient.SqlException
HResult=-2146232060
Message=Incorrect syntax near '('.
Incorrect syntax near the keyword 'WHERE'.
Statement(s) could not be prepared.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=15
LineNumber=1
Number=102
Procedure=""
Server=(local)
State=1
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
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, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
at NHibernate.Persister.Entity.AbstractEntityPersister.Delete(Object id, Object version, Int32 j, Object obj, SqlCommandInfo sql, ISessionImplementor session, Object[] loadedState)