@@ -73,42 +73,50 @@ public Employee(Integer id, String firstName, String lastName) {
7373
7474 @ BeforeEach
7575 protected void setup (EntityManagerFactoryScope scope ) {
76- Session s = scope .getEntityManagerFactory ().unwrap ( SessionFactory .class ).openSession ();
77- s .doWork (
78- connection -> connection .createStatement ().execute (
79- """
80- CREATE ALIAS allEmployeeNames AS $$
81- import org.h2.tools.SimpleResultSet;
82- import java.sql.*;
83- @CODE
84- ResultSet allEmployeeNames() {
85- SimpleResultSet rs = new SimpleResultSet();
86- rs.addColumn("ID", Types.INTEGER, 10, 0);
87- rs.addColumn("FIRSTNAME", Types.VARCHAR, 255, 0);
88- rs.addColumn("LASTNAME", Types.VARCHAR, 255, 0);
89- rs.addRow(1, "Steve", "Ebersole");
90- rs.addRow(1, "Jane", "Doe");
91- rs.addRow(1, "John", "Doe");
92- return rs;
93- }
94- $$"""
95- )
76+ scope .inEntityManager (
77+ entityManager -> {
78+ Session s = scope .getEntityManagerFactory ().unwrap ( SessionFactory .class ).openSession ();
79+ s .doWork (
80+ connection -> connection .createStatement ().execute (
81+ """
82+ CREATE ALIAS allEmployeeNames AS $$
83+ import org.h2.tools.SimpleResultSet;
84+ import java.sql.*;
85+ @CODE
86+ ResultSet allEmployeeNames() {
87+ SimpleResultSet rs = new SimpleResultSet();
88+ rs.addColumn("ID", Types.INTEGER, 10, 0);
89+ rs.addColumn("FIRSTNAME", Types.VARCHAR, 255, 0);
90+ rs.addColumn("LASTNAME", Types.VARCHAR, 255, 0);
91+ rs.addRow(1, "Steve", "Ebersole");
92+ rs.addRow(1, "Jane", "Doe");
93+ rs.addRow(1, "John", "Doe");
94+ return rs;
95+ }
96+ $$"""
97+ )
98+ );
99+ s .close ();
100+ }
96101 );
97102 }
98103
99104 @ AfterEach
100105 public void cleanup (EntityManagerFactoryScope scope ) {
101- Session s = scope .getEntityManagerFactory ().unwrap ( SessionFactory .class ).openSession ();
102- s .doWork (
103- connection -> connection .createStatement ().execute ( "DROP ALIAS allEmployeeNames IF EXISTS" )
104- );
106+ scope .inEntityManager (entityManager -> {
107+ Session s = scope .getEntityManagerFactory ().unwrap ( SessionFactory .class ).openSession ();
108+ s .doWork (
109+ connection -> connection .createStatement ().execute ( "DROP ALIAS allEmployeeNames IF EXISTS" )
110+ );
111+ s .close ();
112+ });
105113 }
106114
107115 @ Test
108116 public void testPartialResults (EntityManagerFactoryScope scope ) {
109117 scope .inTransaction ( em -> {
110118 StoredProcedureQuery query = em .createStoredProcedureQuery ( "allEmployeeNames" , "id-fname-lname" );
111- List results = query .getResultList ();
119+ List <?> results = query .getResultList ();
112120 assertEquals ( 3 , results .size () );
113121 } );
114122 }
0 commit comments