NHibernate 和 NHibernate AJAX 场景中的每次会话会话:需要手动刷新吗?

发布于 2024-11-11 14:58:31 字数 988 浏览 3 评论 0原文

我们的应用程序面临着一个非常奇怪的问题,到目前为止,我看不到解决该问题的选项:

该应用程序在每个会话会话架构中使用 NHibernate (3.1.x),这意味着在每个 ASP/IIS 的开始/结束时请求 NHibernate 会话打开/关闭+刷新/提交新事务。

现在,我们在应用程序中有一个邮箱,包括一个简单的邮件网格: 当用户进入邮箱时,邮件网格首次填充(开始请求创建一个新的 NHibernate 会话/事务,从数据库加载内容,结束请求会话关闭)

删除邮件时出现问题:

(1 ) 邮件的删除不是通过整个页面重新加载/刷新来实现的,而是调用一个 Web 服务,该 Web 服务在删除邮件后返回新呈现的 HTML 网格。 操作来删除邮件

T_Mails m = T_Mails.GetMailByID( 12345678 );
m.Status = MailStatusDeleted;
NHibernateSession.Update( m );

该网络服务通过执行简单的(2) 在调用更新邮件之后,相同的函数还会重新呈现更新后的邮件网格 - 它通过查询表 T_Mails 中的最后 5 行来实现这一点(一个邮箱页面仅包含 5 行!);那么,这就是给定用户的邮箱的当前内容。

现在的问题是: 由于这两个调用都发生在 Web 服务的同一函数中(因此在同一会话/事务范围内),因此我们要删除的邮件(在步骤 1 中)不会被删除,因为 NHibernateSession.Update( m 的更新状态) 未到达数据库。

如果我在调试会话时通过 MSSQL ManagementStudio 打开表,我可以看到邮件的状态未保留到数据库中。

我对这个问题的简单解决方案是: 在更新邮件和从表中重新加载内容之间进行手动 NHibernateSession.Flush() 调用? 但是:这会破坏每个会话的会话模式,因为 NhibernateSession.Flush() 是/应该在每个请求结束时发生 - 不应该在运行请求中的某个地方手动调用它。

否则我真的被困住了。

we are facing a very strange problem with our application, until now i see no option to solve the problem:

The application uses NHibernate (3.1.x) in an session-per-conversation architecture, meaning at start/end of each ASP/IIS request a NHibernate session with a new transaction is opened/closed + flushed/committed.

Now, we have a mailbox in the application including a simple mailgrid:
The mailgrid is populated first time when a user enters the mailbox (start-Request creates a new NHibernate session/transaction, loads stuff from DB, on end-Request the session is closed)

The problem occurs at the deletion of a mail:

(1)
the deletion of mails does not happen via a full page-reload/refresh, instead it calls a webservice which returns the new rendered HTML grid after a message is deleted.
This webservice deletes a mail by doing a simple

T_Mails m = T_Mails.GetMailByID( 12345678 );
m.Status = MailStatusDeleted;
NHibernateSession.Update( m );

(2)
After this call to update the mail, the same function also re-renders the updated mailgrid - it does this by querying for the last 5 rows in table T_Mails (one mailbox page contains only 5 rows!); then, this is the current content of the mailbox for a given user.

The problem now is:
Since both of these calls occur in the same function of the webservice (and thus in the same session/transaction scope), the mail we want to delete (in step 1), is not deleted since the updated status from NHibernateSession.Update( m ) does not reach the database.

If i open the table via MSSQL ManagementStudio while a debugging session i can see that the status of the mail is not persited to database.

My simple solution for this problem would be:
Doing a manual NHibernateSession.Flush() call between updating the mail and reloading the content from the table?
But: this would break the session-per-conversation pattern, since NhibernateSession.Flush() is/should occuring at the end of each request - it's not ought to be called manually somewhere in the running request.

Otherwise i'm really stuck.

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

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

发布评论

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

评论(1

睫毛溺水了 2024-11-18 14:58:31

您应该进行 2 个 ajax 调用 - 第一个调用用于删除项目,第二个调用用于在第一个查询完成时刷新列表。请确保您按照相同的顺序拨打电话。下面是使用 jQuery 的示例代码

$.ajax({
    url: 'Mail/Delete',
    data: { mailId: someId },
    success: function (data) {
        $.ajax({
            url: 'Mail/Refresh',
            success: function (data) {
                //here you should put new list into list container
            }
        });
    }
});

You should make 2 ajax calls - first one to delete an item and second one to refresh list when first query will be finished. Please make sure that you are making calls in same order. Below is sample code using jQuery

$.ajax({
    url: 'Mail/Delete',
    data: { mailId: someId },
    success: function (data) {
        $.ajax({
            url: 'Mail/Refresh',
            success: function (data) {
                //here you should put new list into list container
            }
        });
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文