From 888ade01066aead0517bd6e81250a962a30b028a Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Fri, 1 Dec 2017 15:08:47 -0600 Subject: [PATCH] HHH-12098 - prep 5.3 --- .../test/hql/BulkManipulationTest.java | 44 ++++++------------- .../hibernate/test/hql/CaseStatementTest.java | 19 ++++++++ .../InsertOrderingWithCascadeOnPersist.java | 12 ++--- .../tck2_2/NonSelectQueryLockMode.java | 4 -- .../sql/storedproc/ResultMappingTest.java | 5 --- 5 files changed, 38 insertions(+), 46 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java index 8a6755d363..d90f7d61c9 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java @@ -904,37 +904,19 @@ public class BulkManipulationTest extends BaseCoreFunctionalTestCase { @Test public void testUpdateOnImplicitJoinFails() { - Session s = openSession(); - Transaction t = s.beginTransaction(); - - Human human = new Human(); - human.setName( new Name( "Steve", 'E', null ) ); - - Human mother = new Human(); - mother.setName( new Name( "Jane", 'E', null ) ); - human.setMother( mother ); - - s.save( human ); - s.save( mother ); - s.flush(); - - t.commit(); - - t = s.beginTransaction(); - try { - s.createQuery( "update Human set mother.name.initial = :initial" ).setString( "initial", "F" ).executeUpdate(); - fail( "update allowed across implicit join" ); - } - catch (IllegalArgumentException e) { - assertTyping( QueryException.class, e.getCause() ); - } - catch( QueryException e ) { - } - - s.createQuery( "delete Human where mother is not null" ).executeUpdate(); - s.createQuery( "delete Human" ).executeUpdate(); - t.commit(); - s.close(); + inTransaction( + s -> { + try { + s.createQuery( "update Human set mother.name.initial = :initial" ).setString( "initial", "F" ).executeUpdate(); + fail( "update allowed across implicit join" ); + } + catch (IllegalArgumentException e) { + assertTyping( QueryException.class, e.getCause() ); + } + catch( QueryException e ) { + } + } + ); } @Test diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/CaseStatementTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/CaseStatementTest.java index 21b2453009..a3091c6056 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/CaseStatementTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/CaseStatementTest.java @@ -94,6 +94,25 @@ public class CaseStatementTest extends BaseCoreFunctionalTestCase { .list(); } ); + + inTransaction( + s, + session -> { + try { + s.createQuery( "select case p.name when 'Steve' then :opt1 else :opt2 end from Person p" ) + .setString( "opt1", "x" ) + .setString( "opt2", "y" ) + .list(); + fail( "was expecting an exception" ); + } + catch (IllegalArgumentException e) { + assertTyping( QueryException.class, e.getCause() ); + } + catch (QueryException expected) { + // expected + } + } + ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithCascadeOnPersist.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithCascadeOnPersist.java index 196964ca76..306b04a7a0 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithCascadeOnPersist.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithCascadeOnPersist.java @@ -79,8 +79,8 @@ public class InsertOrderingWithCascadeOnPersist extends BaseCoreFunctionalTestCa @Access(AccessType.FIELD) public static class MarketBid { @Id - @GeneratedValue(strategy = GenerationType.TABLE, generator = "MarketBid") - @TableGenerator(name = "MarketBid", pkColumnValue = "MarketBid", allocationSize = 10000) + @GeneratedValue(strategy = GenerationType.TABLE, generator = "ID_TABLE") + @TableGenerator(name = "ID_TABLE", pkColumnValue = "MarketBid", allocationSize = 10000) private Long id; @ManyToOne(optional = false, cascade = CascadeType.PERSIST) @@ -99,8 +99,8 @@ public class InsertOrderingWithCascadeOnPersist extends BaseCoreFunctionalTestCa @Access(AccessType.FIELD) public static class MarketBidGroup { @Id - @GeneratedValue(strategy = GenerationType.TABLE, generator = "MarketBidGroup") - @TableGenerator(name = "MarketBidGroup", pkColumnValue = "MarketBidGroup", allocationSize = 10000) + @GeneratedValue(strategy = GenerationType.TABLE, generator = "ID_TABLE") + @TableGenerator(name = "ID_TABLE", pkColumnValue = "MarketBidGroup", allocationSize = 10000) private Long id; @OneToMany(mappedBy = "group") @@ -115,8 +115,8 @@ public class InsertOrderingWithCascadeOnPersist extends BaseCoreFunctionalTestCa @Access(AccessType.FIELD) public static class MarketResult { @Id - @GeneratedValue(strategy = GenerationType.TABLE, generator = "MarketResult") - @TableGenerator(name = "MarketResult", pkColumnValue = "MarketResult", allocationSize = 10000) + @GeneratedValue(strategy = GenerationType.TABLE, generator = "ID_TABLE") + @TableGenerator(name = "ID_TABLE", pkColumnValue = "MarketResult", allocationSize = 10000) private Long id; @ManyToOne(optional = false) diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/compliance/tck2_2/NonSelectQueryLockMode.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/compliance/tck2_2/NonSelectQueryLockMode.java index 8f7d0846e7..dd9d1d793d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jpa/compliance/tck2_2/NonSelectQueryLockMode.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/compliance/tck2_2/NonSelectQueryLockMode.java @@ -11,8 +11,6 @@ import javax.persistence.LockModeType; import org.hibernate.test.jpa.AbstractJPATest; import org.junit.Test; -import static org.hibernate.testing.transaction.TransactionUtil2.inTransaction; - /** * @author Steve Ebersole */ @@ -21,7 +19,6 @@ public class NonSelectQueryLockMode extends AbstractJPATest { @Test( expected = IllegalStateException.class ) public void testNonSelectQueryGetLockMode() { inTransaction( - sessionFactory(), session -> session.createQuery( "delete Item" ).getLockMode() ); } @@ -29,7 +26,6 @@ public class NonSelectQueryLockMode extends AbstractJPATest { @Test( expected = IllegalStateException.class ) public void testNonSelectQuerySetLockMode() { inTransaction( - sessionFactory(), session -> session.createQuery( "delete Item" ).setLockMode( LockModeType.PESSIMISTIC_WRITE ) ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/sql/storedproc/ResultMappingTest.java b/hibernate-core/src/test/java/org/hibernate/test/sql/storedproc/ResultMappingTest.java index 4db8e3b682..c36c95a077 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/sql/storedproc/ResultMappingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/sql/storedproc/ResultMappingTest.java @@ -18,7 +18,6 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; -import static org.hibernate.testing.transaction.TransactionUtil2.inTransaction; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -41,7 +40,6 @@ public class ResultMappingTest extends BaseCoreFunctionalTestCase { @Test public void testResultClass() { inTransaction( - sessionFactory(), session -> { final ProcedureCall call = session.createStoredProcedureCall( "findOneUser", @@ -61,7 +59,6 @@ public class ResultMappingTest extends BaseCoreFunctionalTestCase { @Test public void testMappingAllFields() { inTransaction( - sessionFactory(), session -> { final ProcedureCall call = session.createStoredProcedureCall( "findOneUser", "all-fields" ); final ProcedureOutputs procedureResult = call.getOutputs(); @@ -78,7 +75,6 @@ public class ResultMappingTest extends BaseCoreFunctionalTestCase { @Test public void testMappingSomeFields() { inTransaction( - sessionFactory(), session -> { final ProcedureCall call = session.createStoredProcedureCall( "findOneUser", "some-fields" ); final ProcedureOutputs procedureResult = call.getOutputs(); @@ -95,7 +91,6 @@ public class ResultMappingTest extends BaseCoreFunctionalTestCase { @Test public void testMappingNoFields() { inTransaction( - sessionFactory(), session -> { final ProcedureCall call = session.createStoredProcedureCall( "findOneUser", "no-fields" ); final ProcedureOutputs procedureResult = call.getOutputs();