我正在升级到Hibernate 5.3.4。这导致某些集成测试失败。几个表的列名称为id
。这导致CONNECT BY clause required in this query block
错误。
有问题的方法正在使用Criteria查询。这些查询会分解为实际的sql查询,该查询具有sql查询中列出的所有列名,如下例所示。
SELECT
this_.id AS id1_70_0_,
this_.ACCT_ID AS ACCT_ID2_70_0_,
this_.PROD_ID AS PROD_ID3_70_0_,
this_.in_type AS in_type4_70_0_,
this_.set_typ AS set_typ5_70_0_
FROM
SET_TYP this_
WHERE
this_.acct_id IN (
SELECT
acct_id
FROM
account
START WITH
acct_id = 630
CONNECT BY
PRIOR parent_acct_id = acct_id )
如果我删除了Criteria查询并在下面使用sql查询,它将正常工作。
SELECT
*
FROM
SET_TYP
WHERE
acct_id IN (
SELECT
a.acct_id
FROM
account a
START WITH
a.acct_id = 750
CONNECT BY
PRIOR parent_acct_id = a.acct_id )
如何继续使用条件查询?
条件查询如下所示。
Criteria filter = getSession().createCriteria(SetTyp.class);
filter.add(Restrictions.sqlRestriction("acct_id in (select acct_id from account start with acct_id = ?0 connect by prior parent_acct_id = acct_id)", accountId, StandardBasicTypes.INTEGER));
Set<SettleTypeOverride> results = new TreeSet<>();
results.addAll(filter.list());