Search in sources :

Example 1 with CallbackSub2

use of org.datanucleus.samples.annotations.callbacks.CallbackSub2 in project tests by datanucleus.

the class CallbackTest method testExpectionInCallbackNotEaten.

public void testExpectionInCallbackNotEaten() {
    try {
        EntityManager em = getEM();
        EntityTransaction tx = em.getTransaction();
        try {
            tx.begin();
            CallbackSub2 d = new CallbackSub2();
            d.setName("dpt1");
            d.setId("1");
            em.persist(d);
            em.flush();
            fail("Expected ArithmeticException");
        } catch (ArithmeticException ex) {
        // expected
        } finally {
            CallbackBase.invoked.clear();
            CallbackSub1Listener.invoked.clear();
            if (tx.isActive()) {
                tx.rollback();
            }
            em.close();
        }
    } finally {
        clean(CallbackSub2.class);
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) CallbackSub2(org.datanucleus.samples.annotations.callbacks.CallbackSub2)

Aggregations

EntityManager (javax.persistence.EntityManager)1 EntityTransaction (javax.persistence.EntityTransaction)1 CallbackSub2 (org.datanucleus.samples.annotations.callbacks.CallbackSub2)1