Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate NOWAIT不适用于SQLServer2008_Java_Sql_Sql Server_Sql Server 2008_Hibernate - Fatal编程技术网

Java Hibernate NOWAIT不适用于SQLServer2008

Java Hibernate NOWAIT不适用于SQLServer2008,java,sql,sql-server,sql-server-2008,hibernate,Java,Sql,Sql Server,Sql Server 2008,Hibernate,我正在使用Hibernate 3.6.10FINAL,无法为SQLServer2008生成nowait命令。我尝试过使用这两种方言(“SQLServer2008dialent”和“SQLServerdialent”(它们都生成完全不同的SQL查询))但都没有用。我尝试了以下方法: List<TournamentTemplateRecord> leastRecentlyUsedTournaments = s.createCriteria(TournamentTemplateRecord

我正在使用Hibernate 3.6.10FINAL,无法为SQLServer2008生成nowait命令。我尝试过使用这两种方言(“SQLServer2008dialent”和“SQLServerdialent”(它们都生成完全不同的SQL查询))但都没有用。我尝试了以下方法:

List<TournamentTemplateRecord> leastRecentlyUsedTournaments = s.createCriteria(TournamentTemplateRecord.class)
            .addOrder(Order.asc("lastUse"))
            .setMaxResults(5)
            .setLockMode(LockMode.UPGRADE_NOWAIT)
            .setTimeout(0)
            .list();
它们都不会生成nowait查询。这是所有情况下的生成查询:

WITH query AS (select
    ROW_NUMBER() OVER (
order by
    tournament0_.lastuse) as __hibernate_row_nr__,
    tournament0_.combattemplateid as id89_,
    tournament0_1_.combattypeid as combatty2_89_,
    tournament0_1_.combattargetid as combatta3_89_,
    tournament0_1_.resourcenameid as resource4_89_,
    tournament0_1_.resourcedescriptionid as resource5_89_,
    tournament0_1_.rewardloottemplateid as rewardlo6_89_,
    tournament0_1_.combatcontainertypeid as combatco7_89_,
    tournament0_.requirementtemplateid as requirem2_90_,
    tournament0_.assetid as assetid90_,
    tournament0_.durationinsec as duration4_90_,
    tournament0_.lastuse as lastuse90_ 
from
    tournament_tournamenttemplate tournament0_ 
inner join
    readyforcombat_combattemplate tournament0_1_ with (updlock, rowlock) 
        on tournament0_.combattemplateid=tournament0_1_.id ) SELECT
        * 
FROM
    query 
WHERE
    __hibernate_row_nr__ BETWEEN ? AND ?
如何使查询不等待锁定

编辑: 值得一提的是,
.setLockMode(LockMode.UPGRADE\u NOWAIT)
.setLockMode(LockMode.悲观\u WRITE)
生成了相同的精确查询

更新:
我发现这是我使用的hibernate版本中的一个问题。根据这一点,我使用的Hibernate版本(3.6.10Final)中没有修复这一问题。升级Hibernate 4.x对我来说不是一个真正的选择,有没有办法为我的查询手动设置“nowait”提示?

因为这个问题得到了一些投票和视图,我想我应该发布我的解决方案。我最后做了一个本地查询。这并不理想,但它作为一种临时解决方法(即hack)效果良好

for(TournamentTemplateRecord t : leastRecentlyUsedTournaments){
        s.buildLockRequest(LockOptions.UPGRADE).setTimeOut(LockOptions.NO_WAIT).setLockMode(LockMode.UPGRADE_NOWAIT).lock(t);
    }
WITH query AS (select
    ROW_NUMBER() OVER (
order by
    tournament0_.lastuse) as __hibernate_row_nr__,
    tournament0_.combattemplateid as id89_,
    tournament0_1_.combattypeid as combatty2_89_,
    tournament0_1_.combattargetid as combatta3_89_,
    tournament0_1_.resourcenameid as resource4_89_,
    tournament0_1_.resourcedescriptionid as resource5_89_,
    tournament0_1_.rewardloottemplateid as rewardlo6_89_,
    tournament0_1_.combatcontainertypeid as combatco7_89_,
    tournament0_.requirementtemplateid as requirem2_90_,
    tournament0_.assetid as assetid90_,
    tournament0_.durationinsec as duration4_90_,
    tournament0_.lastuse as lastuse90_ 
from
    tournament_tournamenttemplate tournament0_ 
inner join
    readyforcombat_combattemplate tournament0_1_ with (updlock, rowlock) 
        on tournament0_.combattemplateid=tournament0_1_.id ) SELECT
        * 
FROM
    query 
WHERE
    __hibernate_row_nr__ BETWEEN ? AND ?
TournamentTemplateRecord lastActiveTournament = (TournamentTemplateRecord) s.createSQLQuery(
    "SELECT TOP 1 * FROM Tournament_TournamentTemplate tt " +
    "WITH (updlock, rowlock, nowait) " +
    "ORDER BY tt.lastUse desc"
)
    .addEntity(TournamentTemplateRecord.class)
    .uniqueResult();