66 */
77package org .hibernate .test .annotations .embeddables ;
88
9+ import javax .persistence .PersistenceException ;
910import java .math .BigDecimal ;
1011import java .util .ArrayList ;
1112import java .util .Date ;
1617import org .hibernate .SessionFactory ;
1718import org .hibernate .cfg .Configuration ;
1819import org .hibernate .dialect .H2Dialect ;
19- import org .hibernate .exception .GenericJDBCException ;
2020
2121import org .hibernate .testing .RequiresDialect ;
2222import org .hibernate .testing .junit4 .BaseUnitTestCase ;
2323import org .junit .Test ;
2424
25+ import static org .hibernate .testing .junit4 .ExtraAssertions .assertTyping ;
2526import 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