Hi all,
I have an issue using Hibernate @Filter and @SqlFragmentAlias after migration from Hibernate 5.6.9.Final to 6.4.1.Final.
I have defined a filter like this:
@Filter(name = OrderEntity.ORDER_AGENT_FILTER,
condition = "( ({o}.route_id is null and {o}.account_id = :orderAgentAccountId) or ( {o}.route_id is not null and EXISTS(SELECT route_id FROM route r WHERE r.route_id = {o}.route_id and r.vehicle_id = :routeAgentVehicleId ) ) )",
aliases={@SqlFragmentAlias(alias="o", table="\"order\"")},
deduceAliasInjectionPoints = false)
When querying data, all works fine, I can see the SQL generated and {o} is well replaced by alias
where ( (oe1_0.route_id is null and oe1_0.account_id = ?) or ( oe1_0.route_id is not null and EXISTS(SELECT route_id FROM route r WHERE r.route_id = oe1_0.route_id and r.vehicle_id = ? ) ) )
But when executing an update, alias will not replace and sql query contains {o} which causes error on postgres as SQL is malformed
Hibernate: update "order" set state=?,scheduled_date=?,theoretical_arrival_time=?,planned_position=?,cumulated_kilometer=?,route_id=?,unassigned_reason=?,driving_time_to_order=? where order_id=? and ( ({o}.route_id is null and {o}.account_id = ?) or ( {o}.route_id is not null and EXISTS(SELECT route_id FROM route r WHERE r.route_id = {o}.route_id and r.vehicle_id = ? ) ) )
Before migrating, this Filter was working perfectly?.
Am I doing something wrong or is there a bug in this version of Hibernate ?
Thanks for your help.