There is a problem with the parameter binding of dynamic filter parameters in case you use a dynamic filter definition on a OneToMany child collection. The order in which the parameters get bound does not necessarily match the order in which the query defined them.
I am quite new to this so I try to explain as best as I can.
I have a root entity with a filter definition for the deletion timestamp column, and I also apply this filter on its child entities for their deletion timestamp columns:
This is one of the child entites:
Now if I enable the filter in the session:
and execute the following query:
the query will result in the following SQL:
Now watch how the parameters get bound in the wrong order (the dynamic filter is parameter 3 although it should be 1):
I have debugged the code and I found out that although method JoinProcessor#processDynamicFilterParameters() adds the dynamic filter parameters last to the current JOIN, the SQL statement generation happens in the opposite order in method JoinSequence#toJoinFragment() and puts it first:
That is why I would suggest that the easiest bugfix for this is just putting the filter condition in the JoinSequence#toJoinFragment() method to the end as well:
This is a blocker because there is no workaround for that case.
As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.
, I just tested this on the latest build of the 5.0 and 5.1 branches and could not reproduce it based on the information provided. If this still is an ongoing problem, please feel free to include a test case based on https://www.github.com/hibernate/hibernate-test-case-templates.
I don't know if this is the same problem I am facing with 5.1.0 but mine is definitely also related to filters. We have implemented multi-tenancy within one schema using a discriminator clolumn with filters. This worked great with hibernate 4.x. Since the latest upgrade to 5.1.0 the filters' query parameters don't get set resulting in exceptions like the following:
I have tracked it down to QueryParameters line 472 method processFilters:
where the contains condition prevents parameter binding.
This is the filter definition:
Is this bug related or should I open a new issue?
, you might want to backport this to 5.1 and 5.0 too.
Reopening to add more fix versions.