[JIRA] (HHH-16465) CTE query cycle attribute evaluated incorrectly on MSSQL
by MK (JIRA)
MK ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3... ) *commented* on HHH-16465 ( https://hibernate.atlassian.net/browse/HHH-16465?atlOrigin=eyJpIjoiOTI4NG... )
Re: CTE query cycle attribute evaluated incorrectly on MSSQL ( https://hibernate.atlassian.net/browse/HHH-16465?atlOrigin=eyJpIjoiOTI4NG... )
@Christian Beikov
Thank you for working on this. We now came around to testing with 6.2.6 but the test-case we uploaded still fails on MSSQL.
The generated SQL has changed and is now:
with AllParents (child_id,parent_id,groupTreeId,cycleMark, path ) as ( select
g1_0.CHILD_ID,g1_0.PARENT_ID,g1_0.id,0,( char (0)+ coalesce ( cast (g1_0.id as varchar ( max )), char (0))+ char (0)+ char (0))
from
GROUP_TREE_TABLE g1_0
join
GROUP_TABLE c1_0
on c1_0.id=g1_0.CHILD_ID
where
c1_0.id=?
union
all select
g2_0.CHILD_ID,g2_0.PARENT_ID,g2_0.id, case
when cte1_0. path like ( '%' + char (0)+ coalesce ( cast (g2_0.id as varchar ( max )), char (0))+ char (0)+ char (0)+ '%' ) then 1
else 0
end ,(cte1_0. path + char (0)+ coalesce ( cast (g2_0.id as varchar ( max )), char (0))+ char (0)+ char (0))
from
AllParents cte1_0
join
GROUP_TREE_TABLE g2_0
on cte1_0.parent_id=g2_0.CHILD_ID
where
cte1_0.cycleMark=0) select
child1_0.id,
child1_0. NAME ,
parent2_0.id,
parent2_0. NAME ,
ap1_0.groupTreeId,
ap1_0.cycleMark
from
AllParents ap1_0
join
GROUP_TABLE child1_0
on ap1_0.child_id=child1_0.id
join
GROUP_TABLE parent2_0
on ap1_0.parent_id=parent2_0.id
But we still do not get all elements. When we replace char(0) with another character, for example a pipe |, the query works correctly. Somehow MSSQL seems to interpret it incorrectly, as the following query shows:
select char (0) + '11' + char (0) + char (0) as ctePath,
( '%' + char (0) +
coalesce ( cast (1 as varchar ( max )), char (0)) +
char (0) + char (0) + '%' ) as LikeCondition,
case when char (0) + '11' + char (0) + char (0) like
( '%' + char (0) +
coalesce ( cast (1 as varchar ( max )), char (0)) +
char (0) + char (0) + '%' ) then 1
else 0
end as Cycle
The result here is 1 when it should be 0!
Can you please take another look? Thanks in advance!
Just let me know if you need anything else (DB backup, etc.)
( https://hibernate.atlassian.net/browse/HHH-16465#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16465#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100228- sha1:4a42edc )
2 years, 6 months