Hibernate L2 Cache consistency not working properly

Hi,

I’m trying to implement L2 Cache support with Infinispan in my project. However, I encountered an issue with ManyToMany relations—after deleting one entity, the other side of the relation is not updated accordingly.

I’ve created a sample project to demonstrate the problem. It includes:

  • The codebase
  • A Docker Compose setup for the database with the schema
  • IntelliJ IDEA HTTP requests that I use to perform actions (create, cache, remove, and request)

The idea is simple: there are User and Role entities with a ManyToMany relationship. Either entity can be removed, and the goal is to maintain a consistent cache.

Could someone help me investigate this issue?

PS code it there GitHub - bostandyksoft/hibernate-l2 (i can’t find a way to attach it)

@bostandyksoft the application code is always required to manage both sides of bidirectional associations, as you can read from our user guide’s associations chapter:

Whenever a bidirectional association is formed, the application developer must make sure both sides are in-sync at all times.

You can see here an example of bidirectional @ManyToMany mapping using helper methods to ensure syncronicity between both sides of the associations.