从 mssql 迁移到 mysql 时的 Nhibernate 事务问题

发布于 2024-11-25 12:49:20 字数 1169 浏览 2 评论 0原文

我最初使用 Nhibernate 和 MSSQL (2008),一切都运行良好。我有一个 Web 应用程序,它为每个请求绑定一个会话,并将每个工作单元包装在一个事务中。事务是通过 AOP 和自定义属性注入的,因此具有必需属性的所有内容都将包装在以提交或回滚结束的事务中。

再次澄清一下,MSSQL 中的一切都工作正常,并且使用 Nhibernate Profiler,我可以看到所有事务都按预期发生。

现在我刚刚添加了对 Mysql (5.1) 的支持(因为一个环境使用 Mysql 数据库),我已将所有表设置为 InnoDB 并且表结构都是相同的,所以我有点困惑为什么我得到以下信息错误:

Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [SomeRandomEntity#1]Could not synchronize database state with session

检查 Nhibernate 探查器,它正在开始一个事务,触发更新调用,然后抛出错误,而实际上它应该在此时提交。

如果它有助于更​​新中触发的 sql 是(名称已更改):

UPDATE
     some_table SET some_column_1 = 1230697028 /* ?p0 */,
     some_column_2 = '2011-07-21T10:58:59.00' /* ?p1 */ 
WHERE some_column_3 = 1 /* ?p2 */

还值得注意的是,我没有在事务中使用任何隔离级别,我不确定哪一个最适合我的设置,并且当我进行操作时,Mssql 没有抱怨没设置啊

有没有人以前见过这样的问题,因为它现在是一个表演障碍:(

=== 编辑 ===

如果它有帮助,这里是我的连接字符串:

<connectionStrings>
    <add name="NHibernateConnection" connectionString="Server=localhost;Database=xxxxx;Uid=root;" providerName="System.Data.SqlClient"/>
  </connectionStrings>

I was originally using Nhibernate with MSSQL (2008) and everything worked great. I had a web app which bound a session per request and wrapped every unit of work within a transaction. The transactions were injected via AOP and a custom attribute, so everything with the required attribute would be wrapped in a transaction that either ended with a commit or a rollback.

Again just to clarify everything was working fine in MSSQL and using Nhibernate Profiler I can see that all the transactions are occurring as expected.

Now I have just added support for Mysql (5.1) (as one environment uses a Mysql db), I have setup all the tables as InnoDB and the table structures are all identical, so I am a bit baffled as to why I get the following error:

Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [SomeRandomEntity#1]Could not synchronize database state with session

Checking on Nhibernate profiler, it is beginning a transaction, firing an update call then bombing out with the error, whereas really it should be committing at that point.

If it helps the sql being fired in the update is (names changed):

UPDATE
     some_table SET some_column_1 = 1230697028 /* ?p0 */,
     some_column_2 = '2011-07-21T10:58:59.00' /* ?p1 */ 
WHERE some_column_3 = 1 /* ?p2 */

It is also worth noting that I am not using any Isolation Level on my transactions, I wasnt sure which one would be best for my setup and Mssql didnt complain when I didnt set it.

Has anyone seen any issues like this before, as it is a show stopper at the moment :(

=== Edit ===

Incase it helps here is my connection string:

<connectionStrings>
    <add name="NHibernateConnection" connectionString="Server=localhost;Database=xxxxx;Uid=root;" providerName="System.Data.SqlClient"/>
  </connectionStrings>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨曦÷微暖 2024-12-02 12:49:20

问题似乎是由于一个不稳定的列没有插入到其他地方,从而停止了更新。尽管错误并不清楚根本问题是什么。

It seems the problem was down to a wonky column that was not inserting somewhere else, which was stopping the update. Although the error was not really clear as to what the underlying problem was.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文