NServiceBus中的NHibernate - IList <t>或List <t>

时间:2015-10-11 12:35:33

标签: nhibernate nservicebus

我有一个NServiceBus的问题,我首先得到NHibernate无法从NHibernate特定Bag映射的错误,当我把它作为IList时,我得到一条消息,NHibernate找不到这个IList的具体实现。我很难过。

这是我收到的第一个错误:

System.InvalidCastException: Unable to cast object of type
'NHibernate.Collection.Generic.PersistentGenericBag`1[CustomerDirect.Interfaces.Document.DocumentSubTemplate]'
to type
'System.Collections.Generic.List`1[CustomerDirect.Interfaces.Document.DocumentSubTemplate]'.
at (Object , Object[] , SetterCallback )    at
NHibernate.Event.Default.WrapVisitor.ProcessComponent(Object
component, IAbstractComponentType componentType)    at
NHibernate.Event.Default.WrapVisitor.ProcessComponent(Object
component, IAbstractComponentType componentType)    at
NHibernate.Event.Default.WrapVisitor.ProcessValue(Int32 i, Object[]
values, IType[] types)    at
NHibernate.Event.Default.AbstractVisitor.ProcessEntityPropertyValues(Object[]
values, IType[] types)    at
NHibernate.Event.Default.AbstractSaveEventListener.VisitCollectionsBeforeSave(Object
entity, Object id, Object[] values, IType[] types, IEventSource
source)    at
NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate(Object
entity, EntityKey key, IEntityPersister persister, Boolean
useIdentityColumn, Object anything, IEventSource source, Boolean
requiresImmediateIdAccess)    at
NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object
entity, String entityName, Object anything, IEventSource source,
Boolean requiresImmediateIdAccess)    at
NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent
event)    at
NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent
event)    at
NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent
event)    at NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent
event)    at NHibernate.Impl.SessionImpl.Save(Object obj)    at
NServiceBus.Persistence.NHibernate.SharedConnectionStorageSessionProvider.ExecuteInTransaction(Action`1
operation) in
c:\BuildAgent\work\5135de308b2f3016\src\NServiceBus.NHibernate\SharedSession\SharedConnectionStorageSessionProvider.cs:line
60    at NServiceBus.SagaPersistenceBehavior.Invoke(IncomingContext
context, Action next) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Sagas\SagaPersistenceBehavior.cs:line
116    at
ServiceControl.Plugin.SagaAudit.CaptureSagaStateBehavior.Invoke(IncomingContext
context, Action next) in
c:\BuildAgent\work\5d8e2b68f32aa08f\src\ServiceControl.Plugin.SagaAudit\CaptureSagaStateBehavior.cs:line
41    at
NServiceBus.Persistence.NHibernate.OpenNativeTransactionBehavior.Invoke(IncomingContext
context, Action next) in
c:\BuildAgent\work\5135de308b2f3016\src\NServiceBus.NHibernate\SharedSession\OpenNativeTransactionBehavior.cs:line
20    at
NServiceBus.Persistence.NHibernate.OpenSessionBehavior.InnerInvoke(BehaviorContext
context, Action next, Func`1 connectionRetriever) in
c:\BuildAgent\work\5135de308b2f3016\src\NServiceBus.NHibernate\SharedSession\OpenSessionBehavior.cs:line
73    at
NServiceBus.Persistence.NHibernate.OpenSessionBehavior.Invoke(IncomingContext
context, Action next) in
c:\BuildAgent\work\5135de308b2f3016\src\NServiceBus.NHibernate\SharedSession\OpenSessionBehavior.cs:line
35    at NServiceBus.DataBusReceiveBehavior.Invoke(IncomingContext
context, Action next) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\DataBus\DataBusReceiveBehavior.cs:line
60    at
NServiceBus.SetCurrentMessageBeingHandledBehavior.Invoke(IncomingContext
context, Action next) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Unicast\Behaviors\SetCurrentMessageBeingHandledBehavior.cs:line
17    at NServiceBus.LoadHandlersBehavior.Invoke(IncomingContext
context, Action next) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Unicast\Behaviors\LoadHandlersBehavior.cs:line
46    at
NServiceBus.ApplyIncomingMessageMutatorsBehavior.Invoke(IncomingContext
context, Action next) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\MessageMutator\ApplyIncomingMessageMutatorsBehavior.cs:line
23    at
NServiceBus.ExecuteLogicalMessagesBehavior.Invoke(IncomingContext
context, Action next) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Unicast\Messages\ExecuteLogicalMessagesBehavior.cs:line
24    at NServiceBus.CallbackInvocationBehavior.Invoke(IncomingContext
context, Action next) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Unicast\Behaviors\CallbackInvocationBehavior.cs:line
22    at
NServiceBus.DeserializeLogicalMessagesBehavior.Invoke(IncomingContext
context, Action next) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Unicast\Messages\DeserializeLogicalMessagesBehavior.cs:line
47    at
NServiceBus.ApplyIncomingTransportMessageMutatorsBehavior.Invoke(IncomingContext
context, Action next) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\MessageMutator\ApplyIncomingTransportMessageMutatorsBehavior.cs:line
20    at
NServiceBus.SubscriptionReceiverBehavior.Invoke(IncomingContext
context, Action next) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Unicast\Subscriptions\MessageDrivenSubscriptions\SubscriptionReceiverBehavior.cs:line
32    at NServiceBus.UnitOfWorkBehavior.Invoke(IncomingContext
context, Action next) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\UnitOfWork\UnitOfWorkBehavior.cs:line
42    at
NServiceBus.Persistence.NHibernate.OpenSqlConnectionBehavior.Invoke(IncomingContext
context, Action next) in
c:\BuildAgent\work\5135de308b2f3016\src\NServiceBus.NHibernate\SharedSession\OpenSqlConnectionBehavior.cs:line
38    at NServiceBus.ChildContainerBehavior.Invoke(IncomingContext
context, Action next) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Unicast\Behaviors\ChildContainerBehavior.cs:line
17    at
NServiceBus.ProcessingStatisticsBehavior.Invoke(IncomingContext
context, Action next) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Monitoring\ProcessingStatisticsBehavior.cs:line
23    at NServiceBus.AuditBehavior.Invoke(IncomingContext context,
Action next) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Audit\AuditBehavior.cs:line
20    at
NServiceBus.Pipeline.PipelineExecutor.Execute[T](BehaviorChain`1
pipelineAction, T context) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Pipeline\PipelineExecutor.cs:line
127    at
NServiceBus.Unicast.Transport.TransportReceiver.ProcessMessage(TransportMessage
message) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Unicast\Transport\TransportReceiver.cs:line
344    at
NServiceBus.Unicast.Transport.TransportReceiver.TryProcess(TransportMessage
message) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Unicast\Transport\TransportReceiver.cs:line
230    at NServiceBus.Transports.Msmq.MsmqDequeueStrategy.Action() in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Transports\Msmq\MsmqDequeueStrategy.cs:line
266

然后,当我将我的财产变为IList时,我得到了这个:

Exception when starting endpoint.

NHibernate.MappingException: Could not determine type for:
System.Collections.Generic.IList`1[[CustomerDirect.Interfaces.Document.DocumentSubTemplate,
CustomerDirect.Interfaces, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]], mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089, for columns:
NHibernate.Mapping.Column(SubTemplates)

   at NHibernate.Mapping.SimpleValue.get_Type()

   at
NHibernate.Cfg.XmlHbmBinding.MappingLogExtensions.LogMapped(Property
property, IInternalLogger log)

   at NHibernate.Cfg.XmlHbmBinding.PropertiesBinder.Bind(IEnumerable`1
properties, Table table, IDictionary`2 inheritedMetas, Action`1
modifier, Action`1 addToModelAction)

   at
NHibernate.Cfg.XmlHbmBinding.CollectionBinder.BindCompositeElement(HbmCompositeElement
compositeElementMapping, Collection model, IDictionary`2
inheritedMetas)

   at
NHibernate.Cfg.XmlHbmBinding.CollectionBinder.BindCollectionSecondPass(ICollectionPropertiesMapping
collectionMapping, Collection model, IDictionary`2 persistentClasses,
IDictionary`2 inheritedMetas)

   at
NHibernate.Cfg.XmlHbmBinding.CollectionBinder.<>c__DisplayClass13.<AddCollectionSecondPass>b__12(IDictionary`2
persistentClasses)

   at NHibernate.Cfg.Configuration.SecondPassCompile()

   at NHibernate.Cfg.Configuration.BuildSessionFactory()

   at
NServiceBus.Features.NHibernateStorageSession.Setup(FeatureConfigurationContext
context) in
c:\BuildAgent\work\5135de308b2f3016\src\NServiceBus.NHibernate\SharedSession\NHibernateStorageSession.cs:line
54

   at
NServiceBus.Features.FeatureActivator.ActivateFeature(FeatureState
featureState, IEnumerable`1 featuresToActivate,
FeatureConfigurationContext context) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Features\FeatureActivator.cs:line
235

   at
NServiceBus.Features.FeatureActivator.SetupFeatures(FeatureConfigurationContext
context) in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Features\FeatureActivator.cs:line
116

   at NServiceBus.Configure.Initialize() in
c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Configure.cs:line
115

   at NServiceBus.GenericHost.PerformConfiguration(Action`1
moreConfiguration) in
c:\BuildAgent\work\a3de8759ee491634\src\NServiceBus.Hosting.Windows\GenericHost.cs:line
119

   at NServiceBus.GenericHost.Start() in
c:\BuildAgent\work\a3de8759ee491634\src\NServiceBus.Hosting.Windows\GenericHost.cs:line
58

1 个答案:

答案 0 :(得分:0)

我使用NHibernate Loquacious映射使其工作。因为我们从不查询除了saga本身ID之外的Saga数据,所以我在nvarchar(max)字段中使用了Json这样的复杂属性。我用这个要点让它发挥作用:https://gist.github.com/phillip-haydon/1936188