NHibernate 和 NHibernate AJAX 场景中的每次会话会话:需要手动刷新吗?
我们的应用程序面临着一个非常奇怪的问题,到目前为止,我看不到解决该问题的选项:
该应用程序在每个会话会话架构中使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该进行 2 个 ajax 调用 - 第一个调用用于删除项目,第二个调用用于在第一个查询完成时刷新列表。请确保您按照相同的顺序拨打电话。下面是使用 jQuery 的示例代码
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