I am upgrading from Hibernate 5.6.15 to 6.1.7 and have noticed a discrepancy on how the L2 cache works. In 5.6.15, querying using an object parameter correctly reads from the cache, where in 6.1.7 it does not. For example:
Support functions:
We notice that if we change the query to use an id parameter instead of an object parameter, the query would correctly read from the L2 cache (as follows). However, even though we found this workaround, it is still a big problem for our project because we have a huge code base and it would be difficult for us to exhaustively find all queries and ascertain we cover all suspect spots. This is clearly a regression. Whether we use an object or an id as the parameter, L2 query cache should work for either of the two usage patterns.
Here is the full runnable project. HibernateTests is a test suite that demonstrates this. Here is a branch of the project set to Hibernate 5.6.15, showing all tests passing. |