This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/causeway.git
The following commit(s) were added to refs/heads/main by this push:
new 508680c225f CAUSEWAY-3883: potential finishing stage fix
508680c225f is described below
commit 508680c225f1515a35b74580b2f6a2280e0b5f4f
Author: Andi Huber <[email protected]>
AuthorDate: Fri Jun 27 12:09:41 2025 +0200
CAUSEWAY-3883: potential finishing stage fix
- persist and flush entities on async execution finishing
---
.../runtimeservices/wrapper/AsyncExecutionFinisher.java | 15 +++++++++++++--
.../runtimeservices/wrapper/WrapperFactoryDefault.java | 3 ++-
.../integtest/BackgroundService_IntegTestAbstract.java | 3 +--
.../integtests/WrapperFactory_async_IntegTest.java | 3 +--
4 files changed, 17 insertions(+), 7 deletions(-)
diff --git
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/AsyncExecutionFinisher.java
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/AsyncExecutionFinisher.java
index 804c0fdb7d3..7e4c1ade1f1 100644
---
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/AsyncExecutionFinisher.java
+++
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/AsyncExecutionFinisher.java
@@ -20,15 +20,26 @@
import org.apache.causeway.applib.services.repository.RepositoryService;
import org.apache.causeway.applib.services.wrapper.WrapperFactory;
+import org.apache.causeway.applib.services.xactn.TransactionService;
+import org.apache.causeway.core.metamodel.object.MmEntityUtils;
+import org.apache.causeway.core.metamodel.objectmanager.ObjectManager;
record AsyncExecutionFinisher(
WrapperFactory wrapperFactory,
- RepositoryService repositoryService
+ RepositoryService repositoryService,
+ TransactionService transactionService,
+ ObjectManager objectManager
) {
public <T> T finish(T t) {
var pojo = wrapperFactory.unwrap(t);
- return repositoryService.detach(pojo);
+
+ var domainObject = objectManager.adapt(pojo);
+ if(MmEntityUtils.isAttachedEntity(domainObject)) {
+ repositoryService.persistAndFlush(pojo);
+ return repositoryService.detach(pojo);
+ }
+ return pojo;
}
}
diff --git
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/WrapperFactoryDefault.java
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/WrapperFactoryDefault.java
index cbfa29c7b83..4b9b6d31be6 100644
---
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/WrapperFactoryDefault.java
+++
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/WrapperFactoryDefault.java
@@ -115,7 +115,8 @@ public class WrapperFactoryDefault
private ProxyGenerator proxyGenerator;
@Getter(lazy = true) @Accessors(fluent=true)
- private final AsyncExecutionFinisher executionFinisher = new
AsyncExecutionFinisher(this, getRepositoryService());
+ private final AsyncExecutionFinisher executionFinisher =
+ new AsyncExecutionFinisher(this, getRepositoryService(),
getTransactionService(), getObjectManager());
@PostConstruct
public void init() {
diff --git
a/extensions/core/commandlog/applib/src/test/java/org/apache/causeway/extensions/commandlog/applib/integtest/BackgroundService_IntegTestAbstract.java
b/extensions/core/commandlog/applib/src/test/java/org/apache/causeway/extensions/commandlog/applib/integtest/BackgroundService_IntegTestAbstract.java
index fae8a8e4a22..fa1081002c6 100644
---
a/extensions/core/commandlog/applib/src/test/java/org/apache/causeway/extensions/commandlog/applib/integtest/BackgroundService_IntegTestAbstract.java
+++
b/extensions/core/commandlog/applib/src/test/java/org/apache/causeway/extensions/commandlog/applib/integtest/BackgroundService_IntegTestAbstract.java
@@ -131,8 +131,7 @@ void async_using_default_executor_service() {
var control = AsyncControl.defaults();
// when ...
- // return the counter entity, which might not yet have been
persisted,
- // such that we can immediately check whether the action was
executed
+ // returns the detached counter entity, so we can immediately
check whether the action was executed
counter =
wrapperFactory.asyncWrapMixin(Counter_bumpUsingMixin.class, counter, control)
.thenApplyAsync(Counter_bumpUsingMixin::act)
.join(); // wait till done
diff --git
a/regressiontests/core-wrapperfactory/src/test/java/org/apache/causeway/regressiontests/core/wrapperfactory/integtests/WrapperFactory_async_IntegTest.java
b/regressiontests/core-wrapperfactory/src/test/java/org/apache/causeway/regressiontests/core/wrapperfactory/integtests/WrapperFactory_async_IntegTest.java
index 7df220cc30e..192de03e3b2 100644
---
a/regressiontests/core-wrapperfactory/src/test/java/org/apache/causeway/regressiontests/core/wrapperfactory/integtests/WrapperFactory_async_IntegTest.java
+++
b/regressiontests/core-wrapperfactory/src/test/java/org/apache/causeway/regressiontests/core/wrapperfactory/integtests/WrapperFactory_async_IntegTest.java
@@ -106,8 +106,7 @@ void async_using_default_executor_service(final String
displayName, final Execut
.with(executorService);
// when ...
- // return the counter entity, which might not yet have been
persisted,
- // such that we can immediately check whether the action was
executed
+ // returns the detached counter entity, so we can immediately
check whether the action was executed
counter =
wrapperFactory.asyncWrapMixin(Counter_bumpUsingMixin.class, counter,
asyncControl)
.thenApplyAsync(Counter_bumpUsingMixin::act)
// let's wait max 5 sec to allow executor to complete before
continuing