Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
97 additions
and
0 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
...ate-core/src/test/java/org/hibernate/orm/test/query/NativeQuerySchemaPlaceholderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package org.hibernate.orm.test.query; | ||
|
||
import java.util.List; | ||
|
||
import org.hibernate.query.sql.spi.NativeQueryImplementor; | ||
|
||
import org.hibernate.testing.TestForIssue; | ||
import org.hibernate.testing.orm.junit.DomainModel; | ||
import org.hibernate.testing.orm.junit.SessionFactory; | ||
import org.hibernate.testing.orm.junit.SessionFactoryScope; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Tuple; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
@DomainModel( | ||
annotatedClasses = { NativeQuerySchemaPlaceholderTest.TestEntity.class } | ||
) | ||
@SessionFactory | ||
@TestForIssue(jiraKey = "HHH-15269") | ||
public class NativeQuerySchemaPlaceholderTest { | ||
|
||
@BeforeEach | ||
public void setUp(SessionFactoryScope scope) { | ||
scope.inTransaction( | ||
session -> { | ||
TestEntity testEntity = new TestEntity( 1l, "test" ); | ||
session.persist( testEntity ); | ||
} | ||
); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown(SessionFactoryScope scope) { | ||
scope.inTransaction( | ||
session -> { | ||
session.createMutationQuery( "delete from TestEntity" ).executeUpdate(); | ||
} | ||
); | ||
} | ||
|
||
@Test | ||
public void testUpdate(SessionFactoryScope scope) { | ||
scope.inTransaction( | ||
session -> { | ||
NativeQueryImplementor<Tuple> nativeQuery = session.createNativeQuery( | ||
"UPDATE {h-schema}TestEntity SET name = 'updated_test'" | ||
); | ||
nativeQuery.executeUpdate(); | ||
} | ||
); | ||
|
||
scope.inTransaction( | ||
session -> { | ||
List<TestEntity> testEntities = session.createQuery( "from TestEntity", TestEntity.class ) | ||
.list(); | ||
TestEntity testEntity = testEntities.get( 0 ); | ||
assertThat( testEntity.name, is( "updated_test" ) ); | ||
} | ||
); | ||
} | ||
|
||
@Test | ||
public void testSelect(SessionFactoryScope scope) { | ||
scope.inTransaction( | ||
session -> { | ||
NativeQueryImplementor<Long> nativeQuery = session.createNativeQuery( | ||
"select id from {h-schema}TestEntity", Long.class | ||
); | ||
List<Long> results = nativeQuery.list(); | ||
assertThat( results.get( 0 ), is( 1l ) ); | ||
} | ||
); | ||
} | ||
|
||
@Entity(name = "TestEntity") | ||
public static class TestEntity { | ||
@Id | ||
private Long id; | ||
|
||
private String name; | ||
|
||
public TestEntity() { | ||
} | ||
|
||
public TestEntity(Long id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
} | ||
} |