Skip to content

Commit 387d808

Browse files
dhermansonDavideD
authored andcommitted
[#1737] Property parse query string during native select query
1 parent b17eadd commit 387d808

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sql/internal/ReactiveNativeSelectQueryPlanImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public ReactiveNativeSelectQueryPlanImpl(
6060
resultSetMapping.addAffectedTableNames( affectedTableNames, sessionFactory );
6161
}
6262
this.affectedTableNames = affectedTableNames;
63-
this.sql = sql;
63+
this.sql = parser.process();
6464
this.parameterList = parameterList;
6565

6666
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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

Comments
 (0)