Since migrating to Spring Boot 3, I noticed some weird behaviour while using the @Where annotation acting as a soft delete in conjunction with the joined table inheritance pattern.
The basic use case is:
* child entity inheriting from a parent entity using the joined table pattern * The parent entity has a @Where annotation used for detecting a soft delete * the child entity has 2 {{OneToMany}} relations on primary and secondary objects
When trying to get a primary object with a condition on a secondary object going through the child entity, the @Where condition is applied, but the SQL JOIN condition it produces isn’t valid
Here is the SQL produced and the error:
{quote}SELECT P1_0.ID, P1_0.CHILD_ID, P1_0.DATA FROM PRIMARYOBJECT P1_0 JOIN CHILD C1_0 ON C1_0.ID = P1_0.CHILD_ID AND (C1_1.DELETED_ON IS NULL) JOIN SECONDARYOBJECT S1_0 ON C1_0.ID = S1_0.CHILD_ID WHERE S1_0.DATA = ?{quote}
{{ERROR SqlExceptionHelper:150 - Column "C1_1.DELETED_ON" not found}}
Here is the PR to reproduce this behaviour : [https://github.com/hibernate/hibernate-test-case-templates/pull/ 297 300 |https://github.com/hibernate/hibernate-test-case-templates/pull/ 297 300 |smart-link] |
|