Skip to content

Commit 2b962e7

Browse files
author
Thomas Risberg
committed
added unwrapping of scoped proxy tp unwrapResourceIfNecessary() (SPR-5671)
1 parent 68f57aa commit 2b962e7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

org.springframework.transaction/src/main/java/org/springframework/transaction/support/TransactionSynchronizationUtils.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.springframework.core.InfrastructureProxy;
2525
import org.springframework.util.Assert;
26+
import org.springframework.aop.scope.ScopedObject;
2627

2728
/**
2829
* Utility methods for triggering specific {@link TransactionSynchronization}
@@ -55,7 +56,13 @@ public static boolean sameResourceFactory(ResourceTransactionManager tm, Object
5556
*/
5657
static Object unwrapResourceIfNecessary(Object resource) {
5758
Assert.notNull(resource, "Resource must not be null");
58-
return (resource instanceof InfrastructureProxy ? ((InfrastructureProxy) resource).getWrappedObject() : resource);
59+
Object resourceRef = resource;
60+
if (resource instanceof ScopedObject) {
61+
// First unwrap a scoped proxy.
62+
resourceRef = ((ScopedObject) resource).getTargetObject();
63+
}
64+
// Now unwrap infrastructure proxy
65+
return (resourceRef instanceof InfrastructureProxy ? ((InfrastructureProxy) resourceRef).getWrappedObject() : resourceRef);
5966
}
6067

6168

0 commit comments

Comments
 (0)