Bug: Detach entity removes NaturalIdCrossReference in shared cache too
Description
relates to
Activity
Steve Ebersole May 24, 2023 at 1:45 PM
Yes, glad to see you still around
I will take a look.

Guenther Demetz May 23, 2023 at 7:43 AM
Hi Steve,
Glad to hear from you again after so long time & thanks for commenting this.
Can you please take a look at .
I think it contains a neat solution and test-case.
(It still removes the natural-id entry from the natural-id Session (first level) cache anyway)
best regards
Guenther
Steve Ebersole May 16, 2023 at 8:57 PM
An entity is considered associated with the Session if it contains a corresponding “entry”. As detach and clear need to disassociate the entity from the Session, its necessary that their entries are removed. It’s really up to us what we want to do with natural-id caches as that feature is entirely behind the scope of the JPA spec.
That said, I tend to agree that we should not remove the cross-references from the natural-id second-level cache nor do we really need to remove it from the natural-id Session cache.

Guenther Demetz May 4, 2023 at 12:45 PM
Now the pull-request contains also a bug-fix proposal so that the added testcase does not fail anymore.

Guenther Demetz May 2, 2023 at 10:26 AM
Please consider This PR instead to the first one
According JPA Specification the method detach
removes the given entity from the persistence context, causing a managed entity to become detached.
While it might be questionable if detach should also remove the according NaturalIdCrossReference in the persistent context (session.clear does not for instance), for sure it should NOT remove the according NaturalIdCrossReference in the second level cache too.
Pull-Request containing testcase will follow soon...