@Rule
public RequiresTransactionalCapabilitiesRule transactions = new RequiresTransactionalCapabilitiesRule();
@Test
public void testJTAStandalone() throws Exception {
final EntityManagerFactory emf = Persistence.createEntityManagerFactory( "jpajtastandalone", TestHelper.getEnvironmentProperties() );
try {
final EntityManager em = emf.createEntityManager();
try {
em.getTransaction().begin();
Poem poem = new Poem();
poem.setName( "L'albatros" );
em.persist( poem );
em.getTransaction().commit();
em.clear();
em.getTransaction().begin();
Poem poem2 = new Poem();
poem2.setName( "Wazaaaaa" );
em.persist( poem2 );
em.flush();
assertThat( getNumberOfEntities( em ) ).isEqualTo( 2 );
em.getTransaction().rollback();
assertThat( getNumberOfEntities( em ) ).isEqualTo( 1 );
em.getTransaction().begin();
poem = em.find( Poem.class, poem.getId() );
assertThat( poem ).isNotNull();
assertThat( poem.getName() ).isEqualTo( "L'albatros" );
em.remove( poem );
poem2 = em.find( Poem.class, poem2.getId() );
assertThat( poem2 ).isNull();
em.getTransaction().commit();
}
finally {
EntityTransaction transaction = em.getTransaction();
if ( transaction != null && transaction.isActive() ) {
transaction.rollback();
}
em.close();
}
}
finally {
dropSchemaAndDatabase( emf );
emf.close();
}
}