|
| 1 | +/* Hibernate, Relational Persistence for Idiomatic Java |
| 2 | + * |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + * Copyright: Red Hat Inc. and Hibernate Authors |
| 5 | + */ |
| 6 | +package org.hibernate.reactive; |
| 7 | + |
| 8 | +import static java.util.concurrent.TimeUnit.MINUTES; |
| 9 | + |
| 10 | +import io.vertx.junit5.Timeout; |
| 11 | +import io.vertx.junit5.VertxTestContext; |
| 12 | +import jakarta.persistence.Entity; |
| 13 | +import jakarta.persistence.GeneratedValue; |
| 14 | +import jakarta.persistence.Id; |
| 15 | +import jakarta.persistence.Table; |
| 16 | +import java.util.Collection; |
| 17 | +import java.util.List; |
| 18 | +import org.junit.jupiter.api.Assertions; |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | + |
| 21 | +@Timeout(value = 10, timeUnit = MINUTES) |
| 22 | +public class NativeQueryPlaceholderSubstitutionTest extends BaseReactiveTest { |
| 23 | + |
| 24 | + @Override |
| 25 | + protected Collection<Class<?>> annotatedEntities() { |
| 26 | + return List.of(Widget.class); |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + public void testThatSchemaGetsSubstitutedDuringNativeSelectQuery(VertxTestContext context) { |
| 31 | + |
| 32 | + test(context, getSessionFactory().withSession(session -> |
| 33 | + session.createNativeQuery("select count(*) from {h-schema}widgets", Integer.class) |
| 34 | + .getSingleResult() |
| 35 | + .thenAccept(result -> Assertions.assertEquals(0, result)) |
| 36 | + )); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void testThatSchemaGetsSubstitutedDuringNativeNonSelectQuery(VertxTestContext context) { |
| 41 | + |
| 42 | + test(context, getSessionFactory().withSession(session -> |
| 43 | + session.createNativeQuery("update {h-schema}widgets set id = 1") |
| 44 | + .executeUpdate() |
| 45 | + .thenAccept(result -> Assertions.assertEquals(0, result)) |
| 46 | + )); |
| 47 | + } |
| 48 | + |
| 49 | + @Entity(name = "Widget") |
| 50 | + @Table(name = "widgets") |
| 51 | + public static class Widget { |
| 52 | + |
| 53 | + @Id |
| 54 | + @GeneratedValue |
| 55 | + private Long id; |
| 56 | + |
| 57 | + @Override |
| 58 | + public String toString() { |
| 59 | + return "Widget{" + |
| 60 | + "id=" + id + |
| 61 | + '}'; |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | +} |
0 commit comments