Skip to content

Commit 538d7eb

Browse files
dreab8sebersole
authored andcommitted
Fix EmbeddableIntegratorTest
1 parent af3ae95 commit 538d7eb

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/EmbeddableIntegratorTest.java

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

9+
import javax.persistence.PersistenceException;
910
import java.math.BigDecimal;
1011
import java.util.ArrayList;
1112
import java.util.Date;
@@ -16,13 +17,14 @@
1617
import org.hibernate.SessionFactory;
1718
import org.hibernate.cfg.Configuration;
1819
import org.hibernate.dialect.H2Dialect;
19-
import org.hibernate.exception.GenericJDBCException;
2020

2121
import org.hibernate.testing.RequiresDialect;
2222
import org.hibernate.testing.junit4.BaseUnitTestCase;
2323
import org.junit.Test;
2424

25+
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
2526
import static org.junit.Assert.assertEquals;
27+
import static org.junit.Assert.fail;
2628

2729
/**
2830
* @author Chris Pheby
@@ -33,24 +35,31 @@ public class EmbeddableIntegratorTest extends BaseUnitTestCase {
3335
/**
3436
* Throws a mapping exception because DollarValue is not mapped
3537
*/
36-
@Test(expected = JDBCException.class)
38+
@Test
3739
public void testWithoutIntegrator() {
3840
SessionFactory sf = new Configuration().addAnnotatedClass( Investor.class )
3941
.setProperty( "hibernate.hbm2ddl.auto", "create-drop" )
4042
.buildSessionFactory();
4143

4244
try {
4345
Session sess = sf.openSession();
44-
Investor myInv = getInvestor();
45-
myInv.setId( 1L );
46-
47-
sess.save( myInv );
48-
sess.flush();
49-
sess.clear();
50-
51-
Investor inv = (Investor) sess.get( Investor.class, 1L );
52-
assertEquals( new BigDecimal( "100" ), inv.getInvestments().get( 0 ).getAmount().getAmount() );
53-
46+
try {
47+
sess.getTransaction().begin();
48+
Investor myInv = getInvestor();
49+
myInv.setId( 1L );
50+
51+
sess.save( myInv );
52+
sess.flush();
53+
fail("A JDBCException expected");
54+
55+
sess.clear();
56+
57+
Investor inv = (Investor) sess.get( Investor.class, 1L );
58+
assertEquals( new BigDecimal( "100" ), inv.getInvestments().get( 0 ).getAmount().getAmount() );
59+
}catch (PersistenceException e){
60+
assertTyping(JDBCException.class, e.getCause());
61+
sess.getTransaction().rollback();
62+
}
5463
sess.close();
5564
}
5665
finally {
@@ -65,8 +74,9 @@ public void testWithTypeContributor() {
6574
.setProperty( "hibernate.hbm2ddl.auto", "create-drop" )
6675
.buildSessionFactory();
6776

77+
Session sess = sf.openSession();
6878
try {
69-
Session sess = sf.openSession();
79+
sess.getTransaction().begin();
7080
Investor myInv = getInvestor();
7181
myInv.setId( 2L );
7282

@@ -78,6 +88,8 @@ public void testWithTypeContributor() {
7888
assertEquals( new BigDecimal( "100" ), inv.getInvestments().get( 0 ).getAmount().getAmount() );
7989

8090
sess.close();
91+
}catch (Exception e){
92+
sess.getTransaction().rollback();
8193
}
8294
finally {
8395
sf.close();

0 commit comments

Comments
 (0)