我试图将sql查询替换为Oracle,它如下所示:
select trim(a.id) as id from tbl_insttype a where a.chi_city='1' order by cast(a.id as int) for update skip locked
以下是等效的hibernate替换:
Query query=session.createQuery("select trim(a.id) as id from TblInsttype a where a.chiCity='1' order by cast(a.id as int) ");
query.setLockMode( "a",LockMode.UPGRADE);
但我的日志警告说
日志:
12830 [main] DEBUG org.hibernate.hql.internal.ast.ErrorCounter - throwQueryException() : no errors
12846 [main] WARN org.hibernate.dialect.function.TemplateRenderer - HHH000174: Function template anticipated 4 arguments, but 1 arguments encountered
12846 [main] DEBUG org.hibernate.hql.internal.ast.QueryTranslatorImpl - HQL: select trim(a.id) as id from com.imageinfo.eclear.cfg.xml.TblInsttype a where a.chiCity='1' order by cast(a.id as int)
12846 [main] DEBUG org.hibernate.hql.internal.ast.QueryTranslatorImpl - SQL: select trim(tblinsttyp0_.ID) as col_0_0_ from EXPOTDBU_PHILIPPINES.TBL_INSTTYPE tblinsttyp0_ where tblinsttyp0_.CHI_CITY='1' order by cast(tblinsttyp0_.ID as number(10,0))
12846 [main] DEBUG org.hibernate.hql.internal.ast.ErrorCounter - throwQueryException() : no errors
12861 [main] WARN org.hibernate.loader.Loader - HHH000445: Alias-specific lock modes requested, which is not currently supported with follow-on locking; all acquired locks will be [UPGRADE]
12861 [main] WARN org.hibernate.loader.Loader - HHH000444: Encountered request for locking however dialect reports that database prefers locking be done in a separate select (follow-on locking); results will be locked after initial query executes
12877 [main] DEBUG org.hibernate.SQL - select trim(tblinsttyp0_.ID) as col_0_0_ from EXPOTDBU_PHILIPPINES.TBL_INSTTYPE tblinsttyp0_ where tblinsttyp0_.CHI_CITY='1' order by cast(tblinsttyp0_.ID as number(10,0))
Hibernate: select trim(tblinsttyp0_.ID) as col_0_0_ from EXPOTDBU_PHILIPPINES.TBL_INSTTYPE tblinsttyp0_ where tblinsttyp0_.CHI_CITY='1' order by cast(tblinsttyp0_.ID as number(10,0))
12861说了一些明确的话,我没有得到它right.and下面的查询,它也没有任何的更新,跳过锁定在它。
我不明白我做错了什么,我应该尝试一些其他的事情吗?加上--它给不同的lockModes带来了相同的错误。
发布于 2015-12-17 15:54:06
上面写着Alias-specific lock modes requested, which is not currently supported with follow-on locking
,所以我认为你应该尝试一下,不要把你的桌子和a
混在一起。(只有一张桌子,需要吗?)
发布于 2022-05-04 07:55:42
也许HQL解析器没有重新定义别名,您必须将hql从select trim(a.id) as id from tbl_insttype a
更改为select a.id from tbl_insttype a
。
我已经尝试过count(a.id)
查询不支持setLockMode,会抛出could not locate alias to apply lock mode : a
异常。
一个简单的select(a) from Entity a
可以工作。
https://stackoverflow.com/questions/34331218
复制相似问题