Commit 2cb605d
committed
Allow mixing Mutiny.Session and Mutiny.StatelessSession in same transaction
This change removes the artificial restriction that prevented using both
Mutiny.Session and Mutiny.StatelessSession within the same @transactional
method in Hibernate Reactive, bringing it in line with blocking Hibernate ORM.
Key changes:
- Added thread-safe connection reuse in TransactionalContextPool: when a
second session type requests a connection within the same transaction, it
reuses the existing connection from the Vert.x context. Uses VarHandle
with compareAndSet to prevent race conditions when both session types
request connections concurrently.
- Extracted ConnectionHolder as a package-protected class that ensures only
one connection is created per transaction even with concurrent access,
using a Promise pattern inspired by Hibernate Reactive's ProxyConnection
- Made TransactionalContextConnection.close() a no-op to prevent premature
connection closure, letting only TransactionalInterceptorBase close the
actual connection at transaction end
- Changed TransactionalContextPool.getCurrentConnectionFromVertxContext() to
return a Future instead of the connection directly, allowing callers to
handle async connection availability
- Updated TransactionalInterceptorBase.connectionFromContext() to return
Uni<SqlConnection> and all its callers to handle null checks before
converting to Uni
- Updated TransactionalInterceptorBase to use
TransactionalContextPool.closeAndClearCurrentConnection() to properly
close the connection and clear it from the Vert.x context
- Removed validation checks in HibernateReactiveRecorder that threw
IllegalStateException when mixing session types
- Transformed MixStatelessStatefulSessionTest from negative (expecting
failures) to positive tests verifying both session types work together,
share connections, and commit/rollback together
- Updated documentation to explain that mixing is now supported and both
session types share the same underlying connection
Both session types can now coexist in the same transaction, using the
appropriate session type for different operations (e.g., StatelessSession
for bulk operations, regular Session for operations requiring caching).
Fixes #52828
Assisted-By: Claude Code <noreply@anthropic.com>1 parent bbdf6a2 commit 2cb605d
File tree
8 files changed
+265
-146
lines changed- docs/src/main/asciidoc
- extensions
- hibernate-reactive
- deployment/src/test
- java/io/quarkus/hibernate/reactive/transaction/mixing
- resources
- runtime/src/main/java/io/quarkus/hibernate/reactive/runtime
- reactive-transactions/runtime/src/main/java/io/quarkus/reactive/transaction/runtime
- pool
8 files changed
+265
-146
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
492 | 492 | | |
493 | 493 | | |
494 | 494 | | |
495 | | - | |
| 495 | + | |
496 | 496 | | |
497 | 497 | | |
498 | 498 | | |
| |||
Lines changed: 81 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
18 | 23 | | |
19 | 24 | | |
20 | 25 | | |
21 | 26 | | |
22 | 27 | | |
23 | | - | |
| 28 | + | |
24 | 29 | | |
25 | 30 | | |
26 | 31 | | |
27 | 32 | | |
28 | 33 | | |
29 | 34 | | |
30 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
31 | 51 | | |
32 | 52 | | |
33 | 53 | | |
34 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
35 | 57 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
41 | 61 | | |
42 | 62 | | |
43 | 63 | | |
44 | 64 | | |
45 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
46 | 81 | | |
47 | | - | |
| 82 | + | |
48 | 83 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
53 | 91 | | |
54 | 92 | | |
55 | 93 | | |
56 | | - | |
57 | | - | |
58 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
59 | 97 | | |
60 | 98 | | |
61 | 99 | | |
62 | 100 | | |
63 | | - | |
64 | | - | |
65 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
66 | 104 | | |
67 | 105 | | |
68 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
69 | 131 | | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
3 | 6 | | |
4 | 7 | | |
5 | 8 | | |
| |||
Lines changed: 0 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | 137 | | |
149 | 138 | | |
150 | 139 | | |
| |||
179 | 168 | | |
180 | 169 | | |
181 | 170 | | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | 171 | | |
194 | 172 | | |
195 | 173 | | |
| |||
Lines changed: 78 additions & 48 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
112 | 111 | | |
113 | 112 | | |
114 | 113 | | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
121 | 127 | | |
122 | 128 | | |
123 | 129 | | |
| |||
131 | 137 | | |
132 | 138 | | |
133 | 139 | | |
134 | | - | |
135 | | - | |
136 | | - | |
| 140 | + | |
| 141 | + | |
137 | 142 | | |
138 | 143 | | |
139 | | - | |
140 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
141 | 150 | | |
142 | 151 | | |
143 | 152 | | |
144 | 153 | | |
145 | | - | |
146 | | - | |
| 154 | + | |
| 155 | + | |
147 | 156 | | |
148 | 157 | | |
149 | 158 | | |
| |||
152 | 161 | | |
153 | 162 | | |
154 | 163 | | |
155 | | - | |
156 | | - | |
157 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
158 | 174 | | |
159 | 175 | | |
160 | | - | |
| 176 | + | |
161 | 177 | | |
162 | 178 | | |
163 | 179 | | |
164 | 180 | | |
165 | 181 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
171 | 194 | | |
172 | 195 | | |
173 | 196 | | |
174 | 197 | | |
175 | | - | |
176 | | - | |
177 | 198 | | |
178 | 199 | | |
179 | 200 | | |
180 | 201 | | |
181 | 202 | | |
182 | 203 | | |
183 | 204 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
191 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
192 | 220 | | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
206 | 235 | | |
207 | | - | |
208 | | - | |
209 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
210 | 240 | | |
211 | 241 | | |
212 | 242 | | |
| |||
0 commit comments