This is an automated email from the ASF dual-hosted git repository.
jungm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomee.git
The following commit(s) were added to refs/heads/main by this push:
new 96a730fd8c improve EJB keys
96a730fd8c is described below
commit 96a730fd8c436e90d490ebc3ca95c51b659f8c7e
Author: Markus Jung <[email protected]>
AuthorDate: Sat Aug 22 21:04:59 2026 +0200
improve EJB keys
---
.../openejb/core/managed/ManagedContainer.java | 4 ++--
.../openejb/core/stateful/StatefulContainer.java | 4 ++--
.../core/stateful/StatefulContainerTest.java | 21 +++++++++++++++++++++
3 files changed, 25 insertions(+), 4 deletions(-)
diff --git
a/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContainer.java
b/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContainer.java
index a9cc7debdc..5a1fa0741d 100644
---
a/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContainer.java
+++
b/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContainer.java
@@ -74,11 +74,11 @@ import jakarta.transaction.Transaction;
import java.lang.reflect.Method;
import java.rmi.NoSuchObjectException;
import java.rmi.RemoteException;
-import java.rmi.dgc.VMID;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@SuppressWarnings("unchecked")
@@ -437,7 +437,7 @@ public class ManagedContainer implements RpcContainer {
}
protected Object newPrimaryKey() {
- return new VMID();
+ return UUID.randomUUID();
}
protected Object removeEJBObject(final BeanContext beanContext, final
Object primKey, final Class callInterface, final Method callMethod, Object[]
args, final InterfaceType interfaceType) throws OpenEJBException {
diff --git
a/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
b/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
index 8576f7973b..0a6aafc6d9 100644
---
a/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
+++
b/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
@@ -81,11 +81,11 @@ import java.io.Serializable;
import java.lang.reflect.Method;
import java.rmi.NoSuchObjectException;
import java.rmi.RemoteException;
-import java.rmi.dgc.VMID;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
@@ -496,7 +496,7 @@ public class StatefulContainer implements RpcContainer {
}
protected Object newPrimaryKey() {
- return new VMID();
+ return UUID.randomUUID();
}
protected Object removeEJBObject(final BeanContext beanContext, final
Object primKey, final Class callInterface, final Method callMethod, Object[]
args, final InterfaceType interfaceType) throws OpenEJBException {
diff --git
a/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulContainerTest.java
b/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulContainerTest.java
index c424643036..f8ae4e8fce 100644
---
a/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulContainerTest.java
+++
b/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulContainerTest.java
@@ -26,9 +26,11 @@ import
org.apache.openejb.assembler.classic.StatefulSessionContainerInfo;
import org.apache.openejb.assembler.classic.TransactionServiceInfo;
import org.apache.openejb.config.ConfigurationFactory;
import org.apache.openejb.core.LocalInitialContextFactory;
+import org.apache.openejb.core.ivm.BaseEjbProxyHandler;
import org.apache.openejb.jee.EjbJar;
import org.apache.openejb.jee.StatefulBean;
import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.util.proxy.ProxyManager;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
@@ -47,6 +49,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Stack;
+import java.util.UUID;
/**
* @version $Revision$ $Date$
@@ -150,6 +153,24 @@ public class StatefulContainerTest extends TestCase {
testBusinessRemoteInterface(expectedLifecycle);
}
+ public void testPrimaryKeyIsRandomUuid() throws Exception {
+ final InitialContext ctx = new InitialContext();
+ final RemoteWidget first = (RemoteWidget)
ctx.lookup("WidgetBeanRemote");
+ final RemoteWidget second = (RemoteWidget)
ctx.lookup("WidgetBeanRemote");
+ try {
+ final Object firstKey = ((BaseEjbProxyHandler)
ProxyManager.getInvocationHandler(first)).primaryKey;
+ final Object secondKey = ((BaseEjbProxyHandler)
ProxyManager.getInvocationHandler(second)).primaryKey;
+
+ assertTrue("key type", firstKey instanceof UUID);
+ assertTrue("key type", secondKey instanceof UUID);
+ assertEquals("random uuid", 4, ((UUID) firstKey).version());
+ assertFalse("distinct keys", firstKey.equals(secondKey));
+ } finally {
+ first.destroy();
+ second.destroy();
+ }
+ }
+
public void testBusinessLocalInterfaceInTx() throws Exception {
final TransactionManager transactionManager =
SystemInstance.get().getComponent(TransactionManager.class);
transactionManager.begin();