-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OptimisticLockException while using L2 cache fix (#2248)
Under specific conditions is org.eclipse.persistence.exceptions.OptimisticLockException incorrectly thrown. Environment conditions are: JPA L2 cache enabled Weaving is applied to used entities @Version annotation is used Test org.eclipse.persistence.testing.tests.advanced2.weave.WeaveVersionTest#testWeavedEntitiesWithVersionL2Cache describe sequence of steps which leads into org.eclipse.persistence.exceptions.OptimisticLockException if fix is not applied. Purpose of fix in org.eclipse.persistence.internal.sessions.UnitOfWorkImpl#cloneAndRegisterObject(java.lang.Object, org.eclipse.persistence.internal.identitymaps.CacheKey, org.eclipse.persistence.internal.identitymaps.CacheKey, org.eclipse.persistence.descriptors.ClassDescriptor) is update current working object with non-invalidated version from UnitOfWork scope if original is still invalid. Signed-off-by: Radek Felcman <[email protected]>
- Loading branch information
Showing
7 changed files
with
495 additions
and
0 deletions.
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
55 changes: 55 additions & 0 deletions
55
...main/java/org/eclipse/persistence/testing/models/jpa21/advanced/weave/IsolatedEntity.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,55 @@ | ||
/* | ||
* Copyright (c) 2024 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 | ||
*/ | ||
package org.eclipse.persistence.testing.models.jpa21.advanced.weave; | ||
|
||
import java.util.Objects; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import jakarta.persistence.Version; | ||
|
||
@Entity | ||
@Table(name="JPA21_ISOLATED_ENTITY") | ||
public class IsolatedEntity { | ||
|
||
@Id | ||
protected String id; | ||
|
||
@Version | ||
protected Integer version; | ||
|
||
public IsolatedEntity() { | ||
super(); | ||
} | ||
|
||
public IsolatedEntity(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
IsolatedEntity that = (IsolatedEntity) o; | ||
return Objects.equals(id, that.id) && Objects.equals(version, that.version); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, version); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...2/src/main/java/org/eclipse/persistence/testing/models/jpa21/advanced/weave/Location.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) 2024 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 | ||
*/ | ||
package org.eclipse.persistence.testing.models.jpa21.advanced.weave; | ||
|
||
import java.util.Objects; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import jakarta.persistence.Version; | ||
|
||
@Entity | ||
@Table(name="JPA21_LOCATION") | ||
public class Location { | ||
|
||
@Id | ||
protected Long id; | ||
|
||
protected String locationId; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
protected Node node; | ||
|
||
@Version | ||
protected Integer version; | ||
|
||
public Location(long id, String locationId) { | ||
this.id = id; | ||
this.locationId = locationId; | ||
} | ||
|
||
protected Location() { | ||
} | ||
|
||
public Long getId() { | ||
return this.id; | ||
} | ||
|
||
public String getLocationId() { | ||
return this.locationId; | ||
} | ||
|
||
public Node getNode() { | ||
return node; | ||
} | ||
|
||
public void setNode(Node node) { | ||
this.node = node; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Location location = (Location) o; | ||
return Objects.equals(id, location.id) && Objects.equals(locationId, location.locationId) && Objects.equals(node, location.node) && Objects.equals(version, location.version); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, locationId, node, version); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...nced2/src/main/java/org/eclipse/persistence/testing/models/jpa21/advanced/weave/Node.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) 2024 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 | ||
*/ | ||
package org.eclipse.persistence.testing.models.jpa21.advanced.weave; | ||
|
||
import java.util.Objects; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import jakarta.persistence.Version; | ||
|
||
@Entity | ||
@Table(name="JPA21_NODE") | ||
public class Node { | ||
|
||
@Id | ||
protected String id; | ||
|
||
protected int availableBufferCapacity = 10; | ||
|
||
@Version | ||
protected Integer version; | ||
|
||
public Node(String id) { | ||
this.id = id; | ||
} | ||
|
||
protected Node() { | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public int getAvailableBufferCapacity() { | ||
return availableBufferCapacity; | ||
} | ||
|
||
public void reserveBufferCapacity() { | ||
availableBufferCapacity--; | ||
} | ||
|
||
public Integer getVersion() { | ||
return version; | ||
} | ||
|
||
/* | ||
public void setVersion(Integer version) { | ||
this.version = version; | ||
} | ||
*/ | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Node node = (Node) o; | ||
return availableBufferCapacity == node.availableBufferCapacity && Objects.equals(id, node.id) && Objects.equals(version, node.version); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, availableBufferCapacity, version); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...ced2/src/main/java/org/eclipse/persistence/testing/models/jpa21/advanced/weave/Order.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,68 @@ | ||
/* | ||
* Copyright (c) 2024 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 | ||
*/ | ||
package org.eclipse.persistence.testing.models.jpa21.advanced.weave; | ||
|
||
import java.util.Objects; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import jakarta.persistence.Version; | ||
|
||
@Entity | ||
@Table(name="JPA21_ORDER_1") | ||
public class Order { | ||
|
||
@Id | ||
protected Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
protected Node node; | ||
|
||
@Version | ||
protected Integer version; | ||
|
||
protected Order() { | ||
} | ||
|
||
public Order(long id) { | ||
|
||
this.id = id; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public Node getNode() { | ||
return node; | ||
} | ||
|
||
public void setNode(Node destinationNode) { | ||
this.node = destinationNode; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Order order = (Order) o; | ||
return Objects.equals(id, order.id) && Objects.equals(node, order.node) && Objects.equals(version, order.version); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, node, version); | ||
} | ||
} |
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
Oops, something went wrong.