Query cache doesn't recognize changes in many-to-many

Description

I noticed a problem where Hibernate is returning stale date from the query cache if you add an element to a many-to-many relation and there are not other changes and you run a query that joins the two entities. In this case

Hibernate invalidates the query cache region for the many-to-many relation when the element is added
Checks the query cache regions for the two entity tables but completely ingores the cache region for the many-to-many table

2016-02-18 11:38:56 DEBUG UpdateTimestampsCache:87 - Pre-invalidating space [A_B], timestamp: 5962924018069504
2016-02-18 11:38:56 DEBUG UpdateTimestampsCache:123 - Invalidating space [A_B], timestamp: 5962923772317696

2016-02-18 11:39:12 DEBUG StandardQueryCache:155 - Checking cached query results in region: hibernate.test.org.hibernate.cache.internal.StandardQueryCache
2016-02-18 11:39:12 DEBUG StandardQueryCache:253 - Checking query spaces are up-to-date: [A, B]
2016-02-18 11:39:12 DEBUG UpdateTimestampsCache:171 - [A] last update timestamp: 5962923722252288, result set timestamp: 5962923722276865
2016-02-18 11:39:12 DEBUG UpdateTimestampsCache:171 - [B] last update timestamp: 5962923722252288, result set timestamp: 5962923722276865
2016-02-18 11:39:12 DEBUG StandardQueryCache:178 - Returning cached query results

I also noticed another similar problem: when I modify a many-to-many relation and run a query right after that Hibernate doesn't seem to autoflush this change and the query returns the old data. Once I modify another attribute of on of the entities or call flush() manually the query returns the correct data

Environment

None

Assignee

Unassigned

Reporter

Emanuel Kupcik

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure