Java Hibernate HQL queries with nolock

前端 未结 3 1655
执念已碎
执念已碎 2021-02-05 21:07

Is there a way to run these queries as if I added a (NOLOCK) hint to them?

3条回答
  •  佛祖请我去吃肉
    2021-02-05 21:57

    You can do the "with (nolock)" if you go native. This is extreme but if the alternative is changing the transaction isolation level, you might rather do this.

    Note that this example is for MSSQL.

    String sqlQueryString = "SELECT * FROM my_classes_table WITH (nolock) WHERE columnName = :columnValue";
    
    SQLQuery sqlQuery= session.createSQLQuery(sqlQueryString).addEntity(MyClass.class);
    sqlQuery.setLong("columnValue", value);
    List out = sqlQuery.list();
    

提交回复
热议问题