In my application I have to use one filter condition (columnABC=:inputValue) for all SELECT/INSERT/UPDATE/DELETE queries. Column ‘columnABC’ exist in all tables within application.
Filter is attached to session and it is getting appended for all findAll methods.For findById method it was not working so I have applied @Query and filter has attached to it.When I am running save statements filter is not getting attached to the query. What other option I can use to attach filter to update query.
@Service
public class Service1{
@Autowired
private Entity1Repository entity1Repository;
----
----
entity1Repository.save(Entity1);
}
update
table1
set
column1=?,
column2=?,
column3=?,
---
where
column_id=?
There is no way to make this work for update/delete statements. What column does columnABC represent? Is it a tenant identifier? Or a column that is used for table partitioning?
Tenant identifier approach done thru using AbstractRoutingDataSource implementation. In our application we have 2 level data partitioning…One is achieved thru AbstractRoutingDataSource. Second level data separation trying to achieve thru filter approach.
We have two level data separation.One level achieved thru Multitenancy AbstractRoutingDataSource implementation.Second level trying to achieve using @Filter approach which has table partitioning for all select/update/insert/delete operatons
This seems to be a breaking change in hibernate 6 – hibernate 5 did apply a where clause for updates in JPA queries. Ran into this during a spring boot 2 → 3 upgrade.
For example, the following entity manager configuration:
would correctly apply a filter to a JPA query such as UPDATE Services s SET s.isDeleted = true" and append a WHERE tenantId = 1L`. This behavior is broken in hibernate 6.
Did you try using Hibernate 6.2.2.Final already? Pretty sure this was fixed already. If so, please tell the Spring folks to finally do the upgrade to 6.2.