Conventions are not being honored
When using Fluent 1.0.0.363, I had the following Convention applied, which worked fine. Upgrading to anything newer and I get this exception:
FluentNHibernate.Cfg.FluentConfigurationException : An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
----> NHibernate.MappingException : Could not compile the mapping document: (XmlDocument) ----> NHibernate.MappingException : Could not determine type for: MyNS.Price, MyNS for columns: NHibernate.Mapping.Column(PricePerUnit)
I can't stay on .363 through, because the ComponentMap and SubClassMap don't play nice together on that version. Fluent is finding all of my conventions as debugging I see it calling Accept for OTHER properties, but it doesn't ever call it for the Price struct. I have this same problem where i have a UserTypeConvention as well. It works fine in 363, but doesn't get applied in later versions.
Any ideas? Here's the convention:
public sealed class PriceConvention : IPropertyConvention, IPropertyConventionAcceptance {
#region IConventionAcceptance<IPropertyInspector> Members
public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
{
criteria.Expect(x => x.Property.PropertyType == typeof(Price));
}
#endregion
#region IConvention<IPropertyInspector,IPropertyInstance> Members
public void Apply(IPropertyInstance instance)
{
instance.CustomType<decimal>();
instance.CustomSqlType("money");
}
#endregion
}
Support Staff 2 Posted by James Gregory on 21 May, 2010 02:18 PM
Nothing immediately obvious; although I don't understand how
CustomType<decimal>
would ever work, NHibernate wouldn't be able to translate a decimal to Price without an IUserType.Could you attach a project that recreates this issue?
3 Posted by Andy on 21 May, 2010 02:47 PM
Yes, I just finished a project.
It was working with Fluent .363, I thought through the PriceConvention I had setup.
Andy
4 Posted by Andy on 21 May, 2010 02:55 PM
Sorry, the connection string include in the Program.cs is wrong; it should be:
Data Source=:memory:;Version=3;New=True;Pooling=True;Max Pool Size=1;
5 Posted by Andy on 21 May, 2010 03:07 PM
Ok,
I've fixed some unrelated issues in the sample. If you run the one I've attached here you'll encounter the error. Go into the lib folder and rename NFluentHibernate.dll ot something else, and rename the older version to take out the version number. Clean and rerun the solution, and everything works fine.
Thanks
Andy
6 Posted by Andy on 01 Jun, 2010 12:52 PM
Has there been any update on this?
Thanks
Andy
7 Posted by Andy on 18 Jun, 2010 01:59 PM
Hi,
Was just wondering if the sample has been checked out yet? We could be doing something wrong too, but I'd like to get this resolved as we're stuck on .363 with some patches to make things work.
Support Staff 8 Posted by Paul Batum on 27 Jun, 2010 07:00 AM
Hi Andy,
I've taken a look at your sample and I think I can explain why its not
working.
The short of it is that currently, an IPropertyConvention will not be
applied to any properties that exist within a component that was mapped
using a ComponentMap. The reason for this is that if the code applied
conventions to components defined using component maps, there's a good
chance those conventions would be applied more than once because the
component mapping is shared between all the different places it is used.
Applying these conventions more than once is usually harmless but there are
some cases, such as when figuring out the appropriate column names for
component members, where it causes problems.
I've implemented a workaround for this that resolves the issue, but its a
bit of a hack so really I want James to look at it as this ComponentMap
stuff is his baby and he knows it much better than I do. I've sent him a
mail so we'll see what he says. In the mean time, you can try my version of
FNH with the fix here:
http://github.com/paulbatum/fluent-nhibernate/tree/dev
Let me know how it goes.
9 Posted by Andy on 28 Jun, 2010 02:39 PM
Hi Paul,
Thanks for taking the time to look into this. I understand what the issues may be, but I think it's important that this works. Otherwise isn't everyone stuck using types NHibernate natively knows?
Unfortunately the fix didn't work for us; we get a PropertyNotFoundException, as it seems something else goes wrong. Consider this code (Sqlite is not required, as it never gets to the point of building the mappings).
If there's another way we can acomplish what we need to do I'm open to that. Maybe I'm not seeing another solution because I'm just learning Nhibernate & Fluent.
Thanks
Andy
10 Posted by cremor on 29 Jun, 2010 07:46 AM
I think I'm having the same problem. I just updaded from paulbatum-fluent-nhibernate-1.0-testers-2-331-g8294f2a (compiled myself) to 1.1.0.686 (binary download from page) because I also would like to have conventions for ComponentMaps, but now I'm having the problem that the generated mapping XML is invalid.
Instead of creating just the compontent XML node with its sub component and properties as child nodes, it creates many nested component nodes and properties.
Example for correct mapping:
Example of the now produced invalid mapping:
Support Staff 11 Posted by Paul Batum on 30 Jun, 2010 11:25 AM
Okay, yes, there's definitely an issue with my attempted fix, thanks for
letting me know. I'm working on a resolution.
Support Staff 12 Posted by Paul Batum on 30 Jun, 2010 12:09 PM
I've asked James to revert the offending commit. Andy, I'm going to have to
look at your problem a bit more carefully as it looks like my quick fix was
a bad idea.
Sorry for the trouble.
Paul.
13 Posted by Andy on 30 Jun, 2010 12:16 PM
Paul,
No problem, I appreciate you looking into this. Checking out the change was no problem, I just reverted back to our hacked version of fluent.