From 29bb4e3b2f7dcc1483f2fa39bb9bb977fde4307a Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Fri, 19 May 2017 14:04:46 -0700 Subject: [PATCH] HHH-10183 - Fix tests to work pre-5.2 --- .../criterion/NationalizedIgnoreCaseTest.java | 18 +++++++++++---- .../scalar/NationalizedScalarQueryTest.java | 23 +++++++++++++------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/test/criterion/NationalizedIgnoreCaseTest.java b/hibernate-core/src/test/java/org/hibernate/test/criterion/NationalizedIgnoreCaseTest.java index 90377fed10..2d3fefc709 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/criterion/NationalizedIgnoreCaseTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/criterion/NationalizedIgnoreCaseTest.java @@ -12,6 +12,7 @@ import javax.persistence.Id; import javax.persistence.Table; import org.hibernate.Criteria; +import org.hibernate.Session; import org.hibernate.annotations.Nationalized; import org.hibernate.criterion.Restrictions; @@ -24,7 +25,6 @@ import org.junit.Test; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.Assert.assertEquals; /** @@ -48,16 +48,24 @@ public class NationalizedIgnoreCaseTest extends BaseCoreFunctionalTestCase { User user1 = new User(1, "Chris"); User user2 = new User(2, "Steve"); - doInHibernate( this::sessionFactory, session -> { + Session session = openSession(); + session.getTransaction().begin(); + { session.save(user1); session.save(user2); - } ); + } + session.getTransaction().commit(); + session.close(); - doInHibernate( this::sessionFactory, session -> { + session = openSession(); + session.getTransaction().begin(); + { Criteria criteria = session.createCriteria(User.class); criteria.add(Restrictions.eq("name", user1.getName().toLowerCase()).ignoreCase()); assertEquals(1, criteria.list().size()); - } ); + } + session.getTransaction().commit(); + session.close(); } @Entity(name = "User") diff --git a/hibernate-core/src/test/java/org/hibernate/test/scalar/NationalizedScalarQueryTest.java b/hibernate-core/src/test/java/org/hibernate/test/scalar/NationalizedScalarQueryTest.java index 32a07b63e1..54a8351baa 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/scalar/NationalizedScalarQueryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/scalar/NationalizedScalarQueryTest.java @@ -12,6 +12,7 @@ import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; +import org.hibernate.Session; import org.hibernate.annotations.Nationalized; import org.hibernate.dialect.SQLServer2008Dialect; @@ -21,7 +22,6 @@ import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.Assert.assertEquals; /** @@ -43,16 +43,25 @@ public class NationalizedScalarQueryTest extends BaseCoreFunctionalTestCase { User user1 = new User( 1, "Chris" ); User user2 = new User( 2, "Steve" ); - doInHibernate( this::sessionFactory, session -> { + Session session = openSession(); + session.getTransaction().begin(); + { session.save( user1 ); session.save( user2 ); - } ); + } + session.getTransaction().commit(); + session.close(); - doInHibernate( this::sessionFactory, session -> { - List users = session.createNativeQuery( - "select * from users" ).getResultList(); + session = openSession(); + session.getTransaction().begin(); + { + List users = session.createSQLQuery( + "select * from users" + ).list(); assertEquals( 2, users.size() ); - } ); + } + session.getTransaction().commit(); + session.close(); } @Entity(name = "User")