-
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.
OptimisticLockException while using L2 cache fix (#2250)
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
10 changed files
with
528 additions
and
5 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
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
55 changes: 55 additions & 0 deletions
55
...pselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/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.jpa.weave; | ||
|
||
import java.util.Objects; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
import javax.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
jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/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.jpa.weave; | ||
|
||
import java.util.Objects; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.Id; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.Table; | ||
import javax.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
jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/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.jpa.weave; | ||
|
||
import java.util.Objects; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
import javax.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
jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/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.jpa.weave; | ||
|
||
import java.util.Objects; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.Id; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.Table; | ||
import javax.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.