Unable to cast object of type 'NHibernate.Mapping.Formula' to type 'NHibernate.Mapping.Column'.

Description

I have an object mapping where I defined a property that uses a formula. When I try to start the application this is the error message I get with Nhibernate.Envers.

Here is the stack trace.
[InvalidCastException: Unable to cast object of type 'NHibernate.Mapping.Formula' to type 'NHibernate.Mapping.Column'.]
NHibernate.Envers.Tools.MappingTools.<SameColumns>b__0(ISelectable f) +25
System.Linq.WhereSelectListIterator`2.MoveNext() +104
System.Linq.Enumerable.Count(IEnumerable`1 source) +4081813
NHibernate.Envers.Tools.MappingTools.SameColumns(IEnumerable`1 first, IEnumerable`1 second) +200
NHibernate.Envers.Configuration.Store.AuditMappedByMetaDataAdder.createAuditMappedByAttributeIfReferenceImmutable(Collection collectionValue, Property referencedProperty) +70
NHibernate.Envers.Configuration.Store.AuditMappedByMetaDataAdder.addBidirectionalInfo(IDictionary`2 metas) +285
NHibernate.Envers.Configuration.Store.AuditMappedByMetaDataAdder.AddMetaDataTo(IDictionary`2 currentMetaData) +5
NHibernate.Envers.Configuration.Store.MetaDataStore.initializeMetas(IMetaDataProvider metaDataProvider, IEnumerable`1 metaDataAdders) +84
NHibernate.Envers.Configuration.AuditConfiguration..ctor(Configuration cfg, IMetaDataProvider metaDataProvider) +99
NHibernate.Envers.Configuration.AuditConfiguration.GetFor(Configuration cfg) +181
NHibernate.Envers.Event.AuditEventListener.Initialize(Configuration cfg) +10
NHibernate.Event.EventListeners.InitializeListeners(Configuration cfg, Object[] list) +157
NHibernate.Event.EventListeners.InitializeListeners(Configuration cfg) +446
NHibernate.Cfg.Configuration.GetInitializedEventListeners() +75
NHibernate.Cfg.Configuration.BuildSessionFactory() +154
Spring.Data.NHibernate.LocalSessionFactoryObject.NewSessionFactory(Configuration config) in f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Data.NHibernate\Data\NHibernate\LocalSessionFactoryObject.cs:922
Spring.Data.NHibernate.LocalSessionFactoryObject.AfterPropertiesSet() in f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Data.NHibernate\Data\NHibernate\LocalSessionFactoryObject.cs:678
Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InvokeInitMethods(Object target, String name, IConfigurableObjectDefinition definition) in f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:1319
Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) in f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:1872
Spring.Objects.Factory.Support.WebObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) in f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Web\Objects\Factory\Support\WebObjectFactory.cs:450
Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure) in f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:946

Environment

None

Activity

Ismail Seyfi 
January 9, 2014 at 8:27 PM

In this case of where ISelectable is a Formula you get an InvalidCastException.

Ismail Seyfi 
January 9, 2014 at 8:23 PM

I am working on unit case for you but I think the problem is coming from this method.

public static bool SameColumns(IEnumerable<ISelectable> first, IEnumerable<ISelectable> second)
{
var firstNames = from f in first
select ((Column)f).Name;
var lastNames = from s in second
select ((Column)s).Name;
return firstNames.Count() == lastNames.Count() && firstNames.All(f => lastNames.Contains(f));
}

Roger 
May 9, 2013 at 11:30 AM

Missing failing unit test. Closing this issue.

If you can provide a small, failing unit test, please open a new issue with this included.

Roger 
April 13, 2013 at 10:09 AM

Can you attach a failing test please? Either here or (preferably) as a pull request.

Incomplete

Details

Assignee

Reporter

Components

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created April 12, 2013 at 3:42 PM
Updated January 9, 2014 at 8:27 PM
Resolved May 9, 2013 at 11:30 AM
Who's Looking?