Validate queries passed to 'with' method belong to the same scope

Description

I have following entities:

when i try to execute query:

I get following error:

This query works correctly if parameter hibernate.criteria.copy_tree is set to false.

Attachments

1

Activity

Alvaro PedrazaAugust 27, 2024 at 4:00 AM

so the idea would be to improve the with method to avoid this kind of misuse or to provide a better error message? or maybe both?

Honestly I’m not so familiar with the Criteria API but I’ll study this topic a little bit to understand what is happening here and how can be improved. Please do share with me any idea you may have about this improvement.

 

CC:

Marco BelladelliAugust 26, 2024 at 7:09 AM

thanks for the initiative, though this was identified as not a bug - rather a misuse of the with method. As I mentioned in my previous comment, we might do some sort of validation for root / subqueries to only accept CTEs from the right “context”.

I might have lost track of this issue, since this was assigned a sprint a long time ago I can take care of it in the coming days. It would be nice to have a test in the ORM suite, though I believe we can use 's reproducer and build working examples on top of it. I’ll change the issue type to improvement.

Bartlomiej NiemiecAugust 26, 2024 at 6:00 AM

  1. I didn’t find any version in which this example works correctly

  2. I used JDK 17 and JDK 21

I just stumbled upon it by accident during my daily work.

Alvaro PedrazaAugust 23, 2024 at 4:53 AM

:

I’ll give it a try to this one. I have a couple of questions:

  1. Did you checked if this is a regression issue?

  2. Which Java version did you used to reproduce this issue?

Also, any insight you can share with me with any findings or where to start looking, it will be appreciated.

 

CC:

Marco BelladelliJune 5, 2024 at 1:24 PM

We should validate that queries passed as CTEs belong in the same “context”, we could check if they have the same query as parent. For example, if using with for a subquery, allow subqueries from the same parent as CTEs, or if using it for a root query (which has a null parent) require root queries as CTE as well.

Fixed

Details

Assignee

Reporter

Components

Sprint

Fix versions

Priority

Created May 29, 2024 at 7:58 AM
Updated December 3, 2024 at 9:49 AM
Resolved September 13, 2024 at 10:37 AM