Skip to content

Commit a80ceae

Browse files
committed
Merge pull request #1 from dreab8/steve_HHH-10664
Fix DDLWithoutCallbackTest
2 parents e62c085 + 96a8f34 commit a80ceae

29 files changed

+280
-130
lines changed

hibernate-core/src/test/java/org/hibernate/test/annotations/ConfigurationTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88
//$Id$
99
package org.hibernate.test.annotations;
1010

11+
import javax.persistence.PersistenceException;
12+
1113
import org.hibernate.HibernateException;
1214
import org.hibernate.Query;
1315
import org.hibernate.Session;
1416
import org.hibernate.SessionFactory;
1517
import org.hibernate.Transaction;
1618
import org.hibernate.cfg.Configuration;
1719
import org.hibernate.cfg.Environment;
20+
import org.hibernate.hql.internal.ast.QuerySyntaxException;
1821

1922
import org.junit.Test;
2023

24+
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
2125
import static org.junit.Assert.assertEquals;
2226
import static org.junit.Assert.assertNotNull;
2327
import static org.junit.Assert.assertTrue;
@@ -59,7 +63,8 @@ public void testIgnoringHbm() throws Exception {
5963
s.createQuery( "from Boat" ).list();
6064
fail( "Boat should not be mapped" );
6165
}
62-
catch (HibernateException e) {
66+
catch (IllegalArgumentException e) {
67+
assertTyping( QuerySyntaxException.class, e.getCause());
6368
//all good
6469
}
6570
q = s.createQuery( "from Plane" );

hibernate-core/src/test/java/org/hibernate/test/annotations/EntityTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.hibernate.test.annotations;
88

9+
import javax.persistence.PersistenceException;
910
import java.text.DateFormat;
1011
import java.text.SimpleDateFormat;
1112
import java.util.Date;
@@ -221,7 +222,7 @@ public void testUniqueConstraint() throws Exception {
221222
tx.commit();
222223
fail( "unique constraints not respected" );
223224
}
224-
catch (HibernateException e) {
225+
catch (PersistenceException e) {
225226
//success
226227
if ( tx != null ) {
227228
tx.rollback();
@@ -273,8 +274,13 @@ public void testVersion() throws Exception {
273274
tx.commit();
274275
fail( "Optimistic locking should work" );
275276
}
276-
catch (StaleStateException expected) {
277-
// expected exception
277+
catch (PersistenceException expected) {
278+
if ( expected.getCause() instanceof StaleStateException ) {
279+
//expected
280+
}
281+
else {
282+
fail( "StaleStateException expected but is " + expected.getCause() );
283+
}
278284
}
279285
finally {
280286
if ( tx != null ) {

hibernate-core/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLWithoutCallbackTest.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.math.BigDecimal;
1010
import java.util.Map;
11+
import javax.persistence.PersistenceException;
1112
import javax.validation.ConstraintViolationException;
1213

1314
import org.hibernate.Session;
@@ -102,15 +103,19 @@ private void assertDatabaseConstraintViolationThrown(Object o) {
102103
s.flush();
103104
fail( "expecting SQL constraint violation" );
104105
}
105-
catch ( ConstraintViolationException e ) {
106-
fail( "invalid object should not be validated" );
107-
}
108-
catch ( org.hibernate.exception.ConstraintViolationException e ) {
109-
if ( getDialect().supportsColumnCheck() ) {
110-
// expected
106+
catch (PersistenceException pe) {
107+
final Throwable cause = pe.getCause();
108+
if ( cause instanceof ConstraintViolationException ) {
109+
fail( "invalid object should not be validated" );
111110
}
112-
else {
113-
fail( "Unexpected SQL constraint violation [" + e.getConstraintName() + "] : " + e.getSQLException() );
111+
else if ( cause instanceof org.hibernate.exception.ConstraintViolationException ) {
112+
if ( getDialect().supportsColumnCheck() ) {
113+
// expected
114+
}
115+
else {
116+
org.hibernate.exception.ConstraintViolationException cve = (org.hibernate.exception.ConstraintViolationException) cause;
117+
fail( "Unexpected SQL constraint violation [" + cve.getConstraintName() + "] : " + cve.getSQLException() );
118+
}
114119
}
115120
}
116121
tx.rollback();

hibernate-core/src/test/java/org/hibernate/test/annotations/immutable/ImmutableTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.hibernate.test.annotations.immutable;
88

9+
import javax.persistence.PersistenceException;
910
import java.util.ArrayList;
1011
import java.util.List;
1112

@@ -102,9 +103,10 @@ public void testImmutableCollection() {
102103
tx.commit();
103104
fail();
104105
}
105-
catch (HibernateException e) {
106-
assertTrue(e.getMessage().contains("changed an immutable collection instance"));
107-
log.debug("success");
106+
catch ( PersistenceException ex ) {
107+
// expected
108+
assertTrue(ex.getMessage().contains("changed an immutable collection instance"));
109+
log.debug("success");
108110
}
109111
s.close();
110112

@@ -119,7 +121,7 @@ public void testImmutableCollection() {
119121
try {
120122
tx.commit();
121123
fail();
122-
} catch (HibernateException e) {
124+
} catch (PersistenceException e) {
123125
assertTrue(e.getMessage().contains("changed an immutable collection instance"));
124126
log.debug("success");
125127
}

hibernate-core/src/test/java/org/hibernate/test/annotations/join/JoinTest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.hibernate.test.annotations.join;
88

9+
import javax.persistence.PersistenceException;
910
import java.util.ArrayList;
1011
import java.util.Date;
1112
import java.util.Locale;
@@ -18,11 +19,13 @@
1819
import org.hibernate.boot.MetadataBuilder;
1920
import org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl;
2021
import org.hibernate.criterion.Restrictions;
22+
import org.hibernate.exception.ConstraintViolationException;
2123
import org.hibernate.mapping.Join;
2224

2325
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
2426
import org.junit.Test;
2527

28+
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
2629
import static org.junit.Assert.assertEquals;
2730
import static org.junit.Assert.assertNotNull;
2831
import static org.junit.Assert.assertTrue;
@@ -162,9 +165,14 @@ public void testUniqueConstaintOnSecondaryTable() throws Exception {
162165
tx.commit();
163166
fail( "unique constraints violation on secondary table" );
164167
}
165-
catch (HibernateException e) {
166-
//success
167-
tx.rollback();
168+
catch (PersistenceException e) {
169+
try {
170+
assertTyping( ConstraintViolationException.class, e.getCause() );
171+
//success
172+
}
173+
finally {
174+
tx.rollback();
175+
}
168176
}
169177
finally {
170178
s.close();

hibernate-core/src/test/java/org/hibernate/test/annotations/onetomany/OneToManyTest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.hibernate.test.annotations.onetomany;
88

9+
import javax.persistence.PersistenceException;
910
import java.util.ArrayList;
1011
import java.util.Collection;
1112
import java.util.HashSet;
@@ -19,6 +20,7 @@
1920
import org.hibernate.HibernateException;
2021
import org.hibernate.Session;
2122
import org.hibernate.Transaction;
23+
import org.hibernate.exception.ConstraintViolationException;
2224
import org.hibernate.mapping.Column;
2325
import org.hibernate.mapping.PersistentClass;
2426
import org.hibernate.mapping.Table;
@@ -33,6 +35,7 @@
3335
import org.junit.Assert;
3436
import org.junit.Test;
3537

38+
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
3639
import static org.junit.Assert.assertEquals;
3740
import static org.junit.Assert.assertFalse;
3841
import static org.junit.Assert.assertNotNull;
@@ -161,9 +164,15 @@ public void testUnidirectionalDefault() throws Exception {
161164
tx.commit();
162165
fail( "A one to many should not allow several trainer per Tiger" );
163166
}
164-
catch ( HibernateException ce ) {
165-
tx.rollback();
166-
//success
167+
catch (PersistenceException ce) {
168+
try {
169+
assertTyping( ConstraintViolationException.class, ce.getCause() );
170+
//success
171+
172+
}
173+
finally {
174+
tx.rollback();
175+
}
167176
}
168177
s.close();
169178
}

hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OptionalOneToOneMappedByTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77
package org.hibernate.test.annotations.onetoone;
88

9+
import javax.persistence.PersistenceException;
10+
911
import org.junit.Test;
1012

1113
import org.hibernate.Session;
@@ -14,6 +16,7 @@
1416
import org.hibernate.id.IdentifierGenerationException;
1517
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
1618

19+
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
1720
import static org.junit.Assert.assertEquals;
1821
import static org.junit.Assert.assertNotNull;
1922
import static org.junit.Assert.assertNull;
@@ -37,7 +40,8 @@ public void testBidirForeignIdGenerator() {
3740
s.flush();
3841
fail( "should have failed with IdentifierGenerationException" );
3942
}
40-
catch (IdentifierGenerationException ex) {
43+
catch (PersistenceException ex) {
44+
assertTyping(IdentifierGenerationException.class, ex.getCause());
4145
// expected
4246
}
4347
finally {

hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OptionalOneToOnePKJCTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77
package org.hibernate.test.annotations.onetoone;
88

9+
import javax.persistence.PersistenceException;
10+
911
import org.hibernate.Session;
1012
import org.hibernate.Transaction;
1113
import org.hibernate.criterion.Restrictions;
@@ -15,6 +17,7 @@
1517
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
1618
import org.junit.Test;
1719

20+
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
1821
import static org.junit.Assert.assertEquals;
1922
import static org.junit.Assert.assertNotNull;
2023
import static org.junit.Assert.assertNull;
@@ -38,7 +41,8 @@ public void testNullBidirForeignIdGenerator() {
3841
s.flush();
3942
fail( "should have thrown IdentifierGenerationException.");
4043
}
41-
catch ( IdentifierGenerationException ex ) {
44+
catch (PersistenceException ex) {
45+
assertTyping(IdentifierGenerationException.class, ex.getCause());
4246
// expected
4347
}
4448
finally {
@@ -61,7 +65,8 @@ public void testNotFoundBidirForeignIdGenerator() {
6165
s.flush();
6266
fail( "should have thrown IdentifierGenerationException.");
6367
}
64-
catch ( IdentifierGenerationException ex ) {
68+
catch (PersistenceException ex) {
69+
assertTyping(IdentifierGenerationException.class, ex.getCause());
6570
// expected
6671
}
6772
finally {

hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/hhh9798/OneToOneJoinTableTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,25 @@
66
*/
77
package org.hibernate.test.annotations.onetoone.hhh9798;
88

9+
import javax.persistence.PersistenceException;
10+
911
import org.hibernate.Session;
1012
import org.hibernate.Transaction;
13+
import org.hibernate.exception.ConstraintViolationException;
14+
import org.hibernate.id.IdentifierGenerationException;
1115

1216
import org.junit.Test;
1317

1418
import org.hibernate.testing.TestForIssue;
1519
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
1620

21+
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
1722
import static org.junit.Assert.fail;
1823

1924
@TestForIssue(jiraKey = "HHH-9798")
2025
public class OneToOneJoinTableTest extends BaseCoreFunctionalTestCase {
2126

22-
@Test(expected = org.hibernate.exception.ConstraintViolationException.class)
27+
@Test
2328
public void storeNonUniqueRelationship() throws Throwable {
2429
Session session = null;
2530
try {
@@ -38,6 +43,9 @@ public void storeNonUniqueRelationship() throws Throwable {
3843
tx.commit();
3944

4045
fail();
46+
}catch (PersistenceException e){
47+
assertTyping( ConstraintViolationException.class, e.getCause());
48+
// expected
4149
}
4250
finally {
4351
if ( session != null ) {

hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.hibernate.test.annotations.override;
88

9+
import javax.persistence.PersistenceException;
910
import java.util.ArrayList;
1011
import java.util.Collection;
1112
import java.util.List;
@@ -45,7 +46,7 @@ public void testOverriding() throws Exception {
4546
s.flush();
4647
fail( "Should be non nullable" );
4748
}
48-
catch (HibernateException e) {
49+
catch (PersistenceException e) {
4950
//success
5051
}
5152
finally {

0 commit comments

Comments
 (0)