-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Diagnostic new feature - corrupted cache (#1762)
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]>
- Loading branch information
Showing
16 changed files
with
700 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. | ||
This program and the accompanying materials are made available under the | ||
terms of the Eclipse Public License v. 2.0 which is available at | ||
http://www.eclipse.org/legal/epl-2.0, | ||
or the Eclipse Distribution License v. 1.0 which is available at | ||
http://www.eclipse.org/org/documents/edl-v10.php. | ||
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>org.eclipse.persistence.jpa.testapps</artifactId> | ||
<groupId>org.eclipse.persistence</groupId> | ||
<version>4.0.1-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>org.eclipse.persistence.jpa.testapps.diagnostic</artifactId> | ||
|
||
<name>Test - diagnostic</name> | ||
|
||
<properties> | ||
<argLine/> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<executions> | ||
<!--Resolve dependencies into Maven properties like ${org.eclipse.persistence:org.eclipse.persistence.jpa:jar} for JPA module--> | ||
<execution> | ||
<id>get-test-classpath-to-properties</id> | ||
<phase>process-test-classes</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.carlspring.maven</groupId> | ||
<artifactId>derby-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>start-derby</id> | ||
<phase>process-test-classes</phase> | ||
</execution> | ||
<execution> | ||
<id>stop-derby</id> | ||
<phase>prepare-package</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>default-test</id> | ||
<configuration> | ||
<argLine>-javaagent:${org.eclipse.persistence:org.eclipse.persistence.jpa:jar} @{argLine}</argLine> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
77 changes: 77 additions & 0 deletions
77
...rc/main/java/org/eclipse/persistence/testing/models/jpa/diagnostic/BranchADiagnostic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
|
||
// Contributors: | ||
// Oracle - initial API and implementation from Oracle TopLink | ||
package org.eclipse.persistence.testing.models.jpa.diagnostic; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.NamedQueries; | ||
import jakarta.persistence.NamedQuery; | ||
import jakarta.persistence.OneToMany; | ||
import jakarta.persistence.Table; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@NamedQueries({ | ||
@NamedQuery(name = "findBranchADiagnosticById", query = "SELECT bd FROM BranchADiagnostic bd " + "WHERE bd.id = :id")} | ||
) | ||
@Entity | ||
@Table(name = "BRANCHA_DIAGNOSTIC") | ||
public class BranchADiagnostic { | ||
protected int id; | ||
|
||
protected List<BranchBDiagnostic> branchBs; | ||
|
||
public BranchADiagnostic() { | ||
this.branchBs = new ArrayList<>(); | ||
} | ||
/** | ||
* @return the id | ||
*/ | ||
@Id | ||
public int getId() { | ||
return id; | ||
} | ||
|
||
/** | ||
* @param id | ||
* the id to set | ||
*/ | ||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
/** | ||
* @return the branchBs | ||
*/ | ||
@OneToMany(mappedBy = "branchA") | ||
public List<BranchBDiagnostic> getBranchBs() { | ||
return branchBs; | ||
} | ||
|
||
/** | ||
* @param branchBs | ||
* the branchBs to set | ||
*/ | ||
public void setBranchBs(List<BranchBDiagnostic> branchBs) { | ||
this.branchBs = branchBs; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "BranchADiagnostic{" + | ||
"id=" + id + '}'; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...rc/main/java/org/eclipse/persistence/testing/models/jpa/diagnostic/BranchBDiagnostic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
|
||
// Contributors: | ||
// Oracle - initial API and implementation from Oracle TopLink | ||
package org.eclipse.persistence.testing.models.jpa.diagnostic; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
|
||
/** | ||
* Entity implementation class for Entity: BranchA | ||
* | ||
*/ | ||
@Entity | ||
@Table(name = "BRANCHB_DIAGNOSTIC") | ||
public class BranchBDiagnostic { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
protected int id; | ||
protected BranchADiagnostic branchA; | ||
|
||
/** | ||
* @return the id | ||
*/ | ||
@Id | ||
public int getId() { | ||
return id; | ||
} | ||
|
||
/** | ||
* @param id | ||
* the id to set | ||
*/ | ||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
/** | ||
* @return the branchA | ||
*/ | ||
@ManyToOne | ||
@JoinColumn(name = "BRANCHA_FK", nullable = true) | ||
public BranchADiagnostic getBranchA() { | ||
return branchA; | ||
} | ||
|
||
/** | ||
* @param branchA | ||
* the branchA to set | ||
*/ | ||
public void setBranchA(BranchADiagnostic branchA) { | ||
this.branchA = branchA; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "BranchBDiagnostic{" + | ||
"id=" + id + '}'; | ||
} | ||
} |
Oops, something went wrong.