开发者

Fluent NHibernate: Debugging FluentConfigurationException

开发者 https://www.devze.com 2022-12-14 06:28 出处:网络
I\'m enjoying using Fluent NHibernate with AutoMappings but every now and then I get this runtime error when trying to create the fluent configuration: \'An invalid or incomplete configuration was use

I'm enjoying using Fluent NHibernate with AutoMappings but every now and then I get this runtime error when trying to create the fluent configuration: 'An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collections, and InnerException for more detail.'开发者_JAVA技巧

Now this can mean all sorts of things, but the exception details are not very helpful at all. Sometimes the class that NHibernate fails to process will be listed in the InnerException, other times I get mystic messages like this:

{"(XmlDocument)(3,6): XML validation error: The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'property' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements expected: 'meta, subselect, cache, synchronize, comment, tuplizer, id, composite-id' in namespace 'urn:nhibernate-mapping-2.2'."}

That doesnt really help me track down the error. Is there any way to get a detailed log of what NHibernate's trying to do (ie, what class/method it's currently auto-mapping) so I can at least identify the part of my code that is causing the problem?

edit:

Known reasons for this error:

  • database connectivity (should be visible in InnerException detail)
  • missing virtual modifier on properties (should indicate type in InnerException detail)
  • missing ID field (gives non specific error as listed above)


Welcome to the wonderful world of NHibernate debugging! I find the the lack of meaningful error messages one of the most annoying aspects of working with NHibernate. Pretty cool when it works, however.

This is a wild guess, but I've seen this message when I've forgotten to add an "Id" property to one of the classes I'm trying to map.

If you read the error message with this in mind, you'll see that this is one of the things that's potentially missing.


Here's a link that might be useful - debugging nhibernate exceptions. There's mention of setting up logging, but I have not tried it myself.

If you try it, please let us know how you make out.

Another helpful link - troubleshooting common mapping bugs with nhibernate

0

精彩评论

暂无评论...
验证码 换一张
取 消