From d0d6f08243209329132e123f7f6f085f3a8b4cc6 Mon Sep 17 00:00:00 2001 From: Jan Schatteman Date: Tue, 10 Sep 2024 16:10:58 +0200 Subject: [PATCH] Add cleanup method to test Signed-off-by: Jan Schatteman --- .../RegisterNamedQueryWithParameterTest.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/RegisterNamedQueryWithParameterTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/RegisterNamedQueryWithParameterTest.java index d30e4584d2..2f41fd78f5 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/RegisterNamedQueryWithParameterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/RegisterNamedQueryWithParameterTest.java @@ -5,12 +5,12 @@ import java.util.List; import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; import org.hibernate.testing.orm.junit.Jpa; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import jakarta.persistence.Entity; import jakarta.persistence.Id; -import jakarta.persistence.NamedNativeQuery; import jakarta.persistence.Query; import jakarta.persistence.Table; @@ -32,16 +32,23 @@ public class RegisterNamedQueryWithParameterTest { Query query = entityManager.createNativeQuery( QUERY ); scope.getEntityManagerFactory().addNamedQuery( "ENTITY_BY_NAME", query ); - TestEntity entity = new TestEntity( 1l, "And", 1 ); - TestEntity entity2 = new TestEntity( 2l, "Fab", 2 ); + TestEntity entity = new TestEntity( 1L, "And", 1 ); + TestEntity entity2 = new TestEntity( 2L, "Fab", 2 ); entityManager.persist( entity ); entityManager.persist( entity2 ); } ); } + @AfterAll + public void tearDown(EntityManagerFactoryScope scope) { + scope.inTransaction( + entityManager -> entityManager.createQuery( "delete from TestEntity" ).executeUpdate() + ); + } + @Test - public void testExecuteNativQuery(EntityManagerFactoryScope scope) { + public void testExecuteNativeQuery(EntityManagerFactoryScope scope) { scope.inTransaction( entityManager -> { Query query = entityManager.createNamedQuery( QUERY_NAME );