0

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?

Dmitry Duginov
  • 547
  • 2
  • 4
  • 15
  • 1
    ORM's like hibernate have their limits. Once you reach them, it's best to abandon hibernate entirely, at least for the parts where you cross the limits. – Andomar Dec 21 '11 at 16:48

1 Answers1

1

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)

Community
  • 1
  • 1
Dmitry Duginov
  • 547
  • 2
  • 4
  • 15