强制 Hibernate 不使用 sp_execute 进行非查询

发布于 2024-12-22 08:53:44 字数 520 浏览 7 评论 0原文

有没有办法强制 Hibernate 不使用 sp_execute?

考虑这段代码,

String queryString = "SET DEADLOCK_PRIORITY LOW;";
SQLQuery query = session.createSQLQuery(queryString);
return query.executeUpdate();

它变成了sp_prepare,然后是sp_execute,这违背了目的:执行此语句后,会话死锁优先级恢复为NORMAL。

在.NET中,以下代码将执行直接声明并且会话的优先级保持低(根据需要)

command = new SqlCommand("SET DEADLOCK_PRIORITY LOW", _Connection);
command.ExecuteNonQuery();

如何强制 Hibernate 以相同的方式发送声明?

Is there a way to force Hibernate not to use sp_execute?

Consider this code

String queryString = "SET DEADLOCK_PRIORITY LOW;";
SQLQuery query = session.createSQLQuery(queryString);
return query.executeUpdate();

It turns into sp_prepare, then sp_execute and that defeats the purpose: after executing this statement session deadlock priority is back to NORMAL

In .NET the following code would execute the statement directly and priority for the session stays LOW (as desired)

command = new SqlCommand("SET DEADLOCK_PRIORITY LOW", _Connection);
command.ExecuteNonQuery();

How to force Hibernate to send the statement in the same manner?

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

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

发布评论

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

评论(1

悸初 2024-12-29 08:53:44

我找到了一种方法来实现这一点。

String statementText = "SET DEADLOCK_PRIORITY LOW;";
Statement s = session.connection().createStatement();
s.execute(statementText);

但是,connection() 已“已弃用并计划在 Hibernate 4.x 中删除”(已讨论 这里)

I found a way to accomplish that.

String statementText = "SET DEADLOCK_PRIORITY LOW;";
Statement s = session.connection().createStatement();
s.execute(statementText);

However, connection() is "deprecated and scheduled for removal in Hibernate 4.x" (discussed here)

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