Hibernate L2 caching and many-to-many relationships

I have a pair of Hibernate, A, and B objects that are linked by a bidirectional many-to-many relationship, as described here — that is, each object has a bag that references a collection of another type of object, and the link table contains the primary key of each object.

I also use Hibernate L2 caching to cache collection values, for example:

<bag name="xyz" table="XYZ" ...>
    <cache usage="nonstrict-read-write"/>
</bag>

The problem that I find is that when I update the relationship on one side, the cached collection of elements on the other side does not update.

For example:

A a = session.get(1L, A.class);

B b = a.getBs().get(0);
Long bId = b.getId();

a.getBs().remove(0) // delete the B from A
// ... flush and commit the transaction...

B b2 = session.get(bId, B.class);
Collection<A> as = b2.getAs();

a, , . Hibernate .

hibernate - ?

Hibernate 3.2.6.

+3
1

. , .

, .

+1

Source: https://habr.com/ru/post/1708271/


All Articles