Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[master] Diagnostic new feature - corrupted cache #1762

Merged

Conversation

rfelcman
Copy link
Contributor

@rfelcman rfelcman commented Dec 7, 2022

This is new diagnostic feature which could help developers to analyze inconsistent query results. Inconsistent means, that there is mix of managed and detached entities in the query result by logical error in their code. It should happens if JPA L2 caching is enabled.
E.g. let's have following code:

em.remove(branchBDiagnostic);
commitTransaction(em);
//branchBDiagnostic is in Detached state
...
em.getTransaction().begin();
branchADiagnostic.getBranchBs().add(branchBDiagnostic);
branchBDiagnostic.setBranchA(branchADiagnostic);
//Detached entity (branchBDiagnostic) is not persisted again - logical error
commitTransaction(em);

//This em.find() will resolve objects from cache
BranchADiagnostic branchADiagnosticFindResult = em.find(BranchADiagnostic.class, BRANCHA_ID);
...

if cache validation is enabled by
persistence unit property
<property name="eclipselink.query-results-cache.validation" value="true"/>
or by query hint
query.setHint("eclipselink.query-results-cache.validation", true);
EclipseLink will print into log output messages like

[EL Warning]: cache: 2022-12-07 14:26:50.86--UnitOfWork(1211586911)--stack of visited objects that refer to the corrupt object: [BranchADiagnostic{id=1}]
[EL Warning]: cache: 2022-12-07 14:26:50.86--UnitOfWork(1211586911)--corrupt object referenced through mapping: org.eclipse.persistence.mappings.OneToManyMapping[branchBs]
[EL Warning]: cache: 2022-12-07 14:26:50.86--UnitOfWork(1211586911)--corrupt object: BranchBDiagnostic{id=11}

Note: <Entity>.toString() method is used.

Signed-off-by: Radek Felcman [email protected]

Copy link
Member

@lukasj lukasj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rfelcman rfelcman merged commit 2abc9fd into eclipse-ee4j:master Dec 12, 2022
@rfelcman rfelcman deleted the bug_jpa_34609782_CacheCorruption branch December 12, 2022 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants