Fluent 映射和 Spring .NET 事务无法协同工作
我在使用 Fluent、NHibernate 和 Spring.net 时遇到了一个奇怪的问题。我的项目是 ASP.NET MVC 2.0 (.net 4.0) 项目。
我基于 Spring.net Nhibnernate Northwind 项目创建了我的项目。我还按照本页的建议使用基于 Fluent 代码的映射 http://blog.bennymichielsen.be/2009/01/04/using- Fluent-nhibernate-in-spring-net。
当我将 tx:attribute-driven 应用于我的 spring 上下文 xml 文件时,它会破坏应用程序。 LocalSessionFactoryObject 未注入我的 DAO 中。我尝试从上下文中手动提取 SessionFactory,应用程序可以运行,但事务不会回滚。
如果我删除 tx:attribute-driven 属性,应用程序可以运行,但交易当然不会回滚。日志没有显示任何错误。由于应用程序在没有该属性的情况下运行,我猜我的大部分配置应该没问题。
有人成功地将 Fluent、Nhibernate 和 Spring.net 与 Transactions 结合使用吗?
如有必要,我可以提供有关我的设置的更多详细信息。
I am facing a weird problem with Fluent, NHibernate and Spring.net. My project is an ASP.NET MVC 2.0 (.net 4.0) project.
I created my project based on Spring.net Nhibnernate Northwind project. I am also using Fluent code based mappings as suggested on this page http://blog.bennymichielsen.be/2009/01/04/using-fluent-nhibernate-in-spring-net.
When I apply tx:attribute-driven to my spring context xml file, it breaks the application. The LocalSessionFactoryObject is not injected in my DAOs. I tried pulling the SessionFactory manually from the context, the app works but the transactions are not rolled back.
If I remove the tx:attribute-driven attribute, the app works but of course the transactions are not rolled back. The logs dont show any errors. Since the app is working without the attribute, I am guessing most of my configuration should be ok.
Has anyone used a combination of Fluent, Nhibernate and Spring.net successfully with Transactions?
I can provide more details about my setup if necessary.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我自己想出来了。如果其他人在事务或任何 spring 提供的与 AOP 相关的功能方面遇到问题,请确保您是针对接口而不是具体类进行编程。不知怎的,我错过了这个。如果您使用具体类,您的代码将无法使用 Spring 创建的特殊代理,并且 TX 管理等功能将不可用。
I figured it out myself. In case someone else is having problems with Transactions or any spring supplied features related to AOP, please make sure you are programming against Interfaces and not concrete classes. Somehow I was missing this. If you use concrete classes, your code will not be able to use the special proxies created by Spring and the features like TX management will not be available.
@科坦。
如果您的域实体等于数据库表,您可以使用 Nhibernate Fluent 项目中的自动映射...这是自动映射的类...易于使用。看看这个: https://github.com/FluentNHibernate/ Fluent-nhibernate/ wiki/自动映射
@Ketan.
If your domain entities are equals to Database tables, you can use the Automapping inside Nhibernate Fluent project... this is the automapped classes... easy to use. Check this out: https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Auto-mapping