|
5 | 5 | */
|
6 | 6 | package org.hibernate.reactive;
|
7 | 7 |
|
| 8 | +import org.hibernate.reactive.annotations.DisabledFor; |
| 9 | +import org.hibernate.reactive.containers.DatabaseConfiguration; |
| 10 | + |
8 | 11 | import org.junit.jupiter.api.Assertions;
|
9 | 12 | import org.junit.jupiter.api.Test;
|
10 | 13 |
|
|
28 | 31 |
|
29 | 32 | import static java.util.concurrent.TimeUnit.MINUTES;
|
30 | 33 | import static org.assertj.core.api.Assertions.assertThat;
|
| 34 | +import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.POSTGRESQL; |
31 | 35 |
|
32 | 36 | @Timeout(value = 10, timeUnit = MINUTES)
|
33 | 37 |
|
@@ -185,6 +189,55 @@ public void testQueryUpdateWithParameters(VertxTestContext context) {
|
185 | 189 | );
|
186 | 190 | }
|
187 | 191 |
|
| 192 | + @Test |
| 193 | + @DisabledFor( value = POSTGRESQL, reason = "vertx-sql-client issue: https://github.com/eclipse-vertx/vertx-sql-client/issues/1540" ) |
| 194 | + public void testHqlInsertWithTransaction(VertxTestContext context) { |
| 195 | + Integer id = 1; |
| 196 | + String title = "Spell Book: A Comprehensive Guide to Magic Spells and Incantations"; |
| 197 | + test( context, getMutinySessionFactory() |
| 198 | + .withTransaction( session -> session.createMutationQuery( "insert into SpellBook (id, title, forbidden) values (:id, :title, :forbidden)" ) |
| 199 | + .setParameter( "id", id ) |
| 200 | + .setParameter( "title", title ) |
| 201 | + .setParameter( "forbidden", true ) |
| 202 | + .executeUpdate() |
| 203 | + ).call( () -> getMutinySessionFactory() |
| 204 | + .withTransaction( session -> session.createSelectionQuery( "from SpellBook g where g.id = :id ", SpellBook.class ) |
| 205 | + .setParameter( "id", id ) |
| 206 | + .getSingleResult() |
| 207 | + .invoke( spellBook -> { |
| 208 | + assertThat( spellBook.getTitle() ).isEqualTo( title ); |
| 209 | + assertThat( spellBook.forbidden ).isTrue(); |
| 210 | + } |
| 211 | + ) |
| 212 | + ) |
| 213 | + ) |
| 214 | + ); |
| 215 | + } |
| 216 | + |
| 217 | + @Test |
| 218 | + public void testHqlInsertWithoutTransaction(VertxTestContext context) { |
| 219 | + Integer id = 1; |
| 220 | + String title = "Spell Book: A Comprehensive Guide to Magic Spells and Incantations"; |
| 221 | + test( context, getMutinySessionFactory() |
| 222 | + .withSession( session -> session.createMutationQuery( "insert into SpellBook (id, title, forbidden) values (:id, :title, :forbidden)" ) |
| 223 | + .setParameter( "id", id ) |
| 224 | + .setParameter( "title", title ) |
| 225 | + .setParameter( "forbidden", true ) |
| 226 | + .executeUpdate() |
| 227 | + ).call( () -> getMutinySessionFactory() |
| 228 | + .withTransaction( session -> session.createSelectionQuery( "from SpellBook g where g.id = :id ", SpellBook.class ) |
| 229 | + .setParameter( "id", id ) |
| 230 | + .getSingleResult() |
| 231 | + .invoke( spellBook -> { |
| 232 | + assertThat( spellBook.getTitle() ).isEqualTo( title ); |
| 233 | + assertThat( spellBook.forbidden ).isTrue(); |
| 234 | + } |
| 235 | + ) |
| 236 | + ) |
| 237 | + ) |
| 238 | + ); |
| 239 | + } |
| 240 | + |
188 | 241 | @Entity(name="SpellBook")
|
189 | 242 | @Table(name = "SpellBookJS")
|
190 | 243 | @DiscriminatorValue("S")
|
|
0 commit comments