Hibernate query being cached wrong

2019-03-02 06:12发布

The below query is in my AuthorizedVoter and gets fired first before i access my API. This returns 1 result.

    " from School s inner join fetch s.student ss where s.Key = :schoolKey and      " +
        "s.accountKey = :accountKey and ss.Key= :studentKey " +
        "and ss.country='INDIA'"

The API fires the below query, The result from this query is also 1 row

SELECT DISTINCT
s.key, ss.studentkey
FROM
school s
    INNER JOIN
student ss ON s.key = ss.reportingsessionkey
    AND (ss.country='INDIA')
WHERE
session0_.key = ?

If i evict the cache, the return is 4 rows, which is the actual correct value. I am not using any second level cache, It seems to be a first level cache problem. Please help me find a better fix than evicting the cache in the API. Also what is the actual reason.

To add more to this when I run the 2 queries as a part of integration test one after the another results are fine. The first query is part of Spring security and the second part of the API which would get called after that, It seems that somehow the student details are stored in the persistence context and continue to be used in the API.

Please find the link to the code on gihub https://github.com/agandhinit/crazy-hibernate

0条回答
登录 后发表回答