Fluent NHibernate:调试 FluentConfigurationException
我很喜欢将 Fluent NHibernate 与 AutoMappings 一起使用,但在尝试创建流畅配置时,我时不时会遇到此运行时错误:“创建 SessionFactory 时使用了无效或不完整的配置。检查 PotentialReasons 集合和 InnerException 以获取更多详细信息。'
现在这可能意味着各种各样的事情,但异常详细信息根本没有多大帮助。有时 NHibernate 无法处理的类会在 InnerException 中列出,有时我会收到如下神秘消息:
{"(XmlDocument)(3,6): XML 验证错误: 命名空间中的元素 'class' ' urn:nhibernate-mapping-2.2' 在命名空间 'urn:nhibernate-mapping-2.2' 中具有无效的子元素 'property'。预期可能的元素列表:'meta、subselect、cache、synchronize、comment、tuplizer、id、composite- id' 在命名空间 'urn:nhibernate-mapping-2.2' 中。"}
这并不能真正帮助我追踪错误。有没有办法获得 NHibernate 尝试执行的操作的详细日志(即当前自动映射的类/方法),以便我至少可以识别导致问题的代码部分?
编辑:
此错误的已知原因:
- 数据库连接(应在 InnerException 详细信息中可见)
- 缺少属性上的虚拟修饰符(应指示 InnerException 详细信息中的类型)
- 缺少 ID 字段(给出上面列出的非特定错误)
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.'
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
欢迎来到 NHibernate 调试的奇妙世界!我发现缺乏有意义的错误消息是使用 NHibernate 时最烦人的方面之一。然而,当它工作时非常酷。
这是一个疯狂的猜测,但当我忘记向我尝试映射的类之一添加“Id”属性时,我看到了此消息。
如果您在阅读错误消息时牢记这一点,您会发现这是可能缺少的内容之一。
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.
这是一个可能有用的链接 - 调试 nhibernate例外。有提到设置日志记录,但我自己没有尝试过。
如果您尝试一下,请告诉我们您的结果。
另一个有用的链接 - 使用 nhibernate 排除常见映射错误
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