/** * Make a best effort to mark the underlying transaction for rollback only. */ default void markRollbackOnly() { setRollbackOnly(); }
@Test public void testMapsIdJoinColumnOneToOneSelectException() { setupTest( PersonMapsIdColumnSelectException.class, 1L, true ); doInHibernate( this::sessionFactory, session -> { Person pCheck = session.find( PersonMapsIdColumnSelectException.class, 1L ); assertNotNull( pCheck ); assertFalse( Hibernate.isInitialized( pCheck.getCity() ) ); try { Hibernate.initialize( pCheck.getCity() ); fail( "Should have thrown ObjectNotFoundException" ); } catch (ObjectNotFoundException expected) { session.getTransaction().setRollbackOnly(); } } ); }
@Test public void testMapsIdOneToOneSelectException() { setupTest( PersonMapsIdSelectException.class, 1L, true ); doInHibernate( this::sessionFactory, session -> { Person pCheck = session.find( PersonMapsIdSelectException.class, 1L ); assertNotNull( pCheck ); assertFalse( Hibernate.isInitialized( pCheck.getCity() ) ); try { Hibernate.initialize( pCheck.getCity() ); fail( "Should have thrown ObjectNotFoundException" ); } catch (ObjectNotFoundException expected) { session.getTransaction().setRollbackOnly(); } } ); }
@Test public void testMapsIdJoinColumnOneToOneSelectException() { setupTest( PersonMapsIdColumnSelectException.class, 1L, true ); doInHibernate( this::sessionFactory, session -> { Person pCheck = session.find( PersonMapsIdColumnSelectException.class, 1L ); assertNotNull( pCheck ); assertFalse( Hibernate.isInitialized( pCheck.getCity() ) ); try { Hibernate.initialize( pCheck.getCity() ); fail( "Should have thrown ObjectNotFoundException" ); } catch (ObjectNotFoundException expected) { session.getTransaction().setRollbackOnly(); } } ); }
@Test public void testManyToOneSelectException() { setupTest( PersonManyToOneSelectException.class, 1L, false ); doInHibernate( this::sessionFactory, session -> { Person pCheck = session.find( PersonManyToOneSelectException.class, 1L ); assertNotNull( pCheck ); assertFalse( Hibernate.isInitialized( pCheck.getCity() ) ); try { Hibernate.initialize( pCheck.getCity() ); fail( "Should have thrown ObjectNotFoundException" ); } catch (ObjectNotFoundException expected) { session.getTransaction().setRollbackOnly(); } } ); }
@Test public void testMapsIdOneToOneSelectException() { setupTest( PersonMapsIdSelectException.class, 1L, true ); doInHibernate( this::sessionFactory, session -> { Person pCheck = session.find( PersonMapsIdSelectException.class, 1L ); assertNotNull( pCheck ); assertFalse( Hibernate.isInitialized( pCheck.getCity() ) ); try { Hibernate.initialize( pCheck.getCity() ); fail( "Should have thrown ObjectNotFoundException" ); } catch (ObjectNotFoundException expected) { session.getTransaction().setRollbackOnly(); } } ); }
@Test public void testOneToOneSelectException() { setupTest( PersonOneToOneSelectException.class, 1L, false ); doInHibernate( this::sessionFactory, session -> { Person pCheck = session.find( PersonOneToOneSelectException.class, 1L ); assertNotNull( pCheck ); assertFalse( Hibernate.isInitialized( pCheck.getCity() ) ); try { Hibernate.initialize( pCheck.getCity() ); fail( "Should have thrown ObjectNotFoundException" ); } catch (ObjectNotFoundException expected) { session.getTransaction().setRollbackOnly(); } } ); }
@Test public void testOneToOneSelectException() { setupTest( PersonOneToOneSelectException.class, 1L, false ); doInHibernate( this::sessionFactory, session -> { Person pCheck = session.find( PersonOneToOneSelectException.class, 1L ); assertNotNull( pCheck ); assertFalse( Hibernate.isInitialized( pCheck.getCity() ) ); try { Hibernate.initialize( pCheck.getCity() ); fail( "Should have thrown ObjectNotFoundException" ); } catch (ObjectNotFoundException expected) { session.getTransaction().setRollbackOnly(); } } ); }
@Test public void testManyToOneSelectException() { setupTest( PersonManyToOneSelectException.class, 1L, false ); doInHibernate( this::sessionFactory, session -> { Person pCheck = session.find( PersonManyToOneSelectException.class, 1L ); assertNotNull( pCheck ); assertFalse( Hibernate.isInitialized( pCheck.getCity() ) ); try { Hibernate.initialize( pCheck.getCity() ); fail( "Should have thrown ObjectNotFoundException" ); } catch (ObjectNotFoundException expected) { session.getTransaction().setRollbackOnly(); } } ); }
@Test public void testPkjcOneToOneSelectException() { setupTest( PersonPkjcSelectException.class, 1L, false ); doInHibernate( this::sessionFactory, session -> { Person pCheck = session.find( PersonPkjcSelectException.class, 1L ); assertNotNull( pCheck ); assertFalse( Hibernate.isInitialized( pCheck.getCity() ) ); try { Hibernate.initialize( pCheck.getCity() ); fail( "Should have thrown ObjectNotFoundException" ); } catch (ObjectNotFoundException expected) { session.getTransaction().setRollbackOnly(); } } ); }
assertTrue( transaction.isActive() ); transaction.setRollbackOnly(); assertTrue( transaction.isActive() ); assertTrue( transaction.getRollbackOnly() ); assertTrue( transaction.isActive() ); transaction.setRollbackOnly(); assertTrue( transaction.isActive() ); assertTrue( transaction.getRollbackOnly() );
assertFalse( transaction.isActive() ); try { transaction.setRollbackOnly(); fail( "Expecting failure #setRollbackOnly on non-active txn" );
/** * Make a best effort to mark the underlying transaction for rollback only. */ default void markRollbackOnly() { setRollbackOnly(); }
@Override public void setRollbackOnly() { transaction.setRollbackOnly(); }