Add cleanup method to test

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2024-09-10 16:10:58 +02:00 committed by Jan Schatteman
parent 8da3f3700f
commit d0d6f08243
1 changed files with 11 additions and 4 deletions

View File

@ -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 );