0

I am using hibernate jpa to perform a batch update .

Its not giving any error or exceptions but the transaction roll backs everytime giving.

2015-04-21 16:30:33,548 ERROR [org.jboss.as.ejb3] (Thread-344 (HornetQ-client-global-threads-462057890)) javax.ejb.EJBTransactionRolledbackException: no transaction is in progress

This is my batch update code

getEm().getTransaction().begin();
    System.out.println("transaction started--------------");
    try{    
    for(Receipt ReceiptEntity : arrReceiptEntity){


        getEm().persist(ReceiptEntity);


    }
    getEm().getTransaction().commit();
    System.out.println("commited");
    }catch(Exception exception){
        System.out.println("error----------------------------------------------------------------------");
        if(getEm().getTransaction().isActive())
            getEm().getTransaction().rollback();
            LOG.error(exception);
    }finally
    {
        getEm().flush();
        getEm().clear();
        getEm().close();
    }

I am using Postgres server 9.4.1 Please help me figure out what i am doing wrong. I have checked other similar posts but nothing helped.

UPDATE: I got the solution: The problem was I was flushing the already flushed transaction.And thus it was giving me no transaction in progress error along with the one i posted above.So i just removed the `getEm().flush(); and getEm().clear(); from the finally block and it started working :)

kirti
  • 4,499
  • 4
  • 31
  • 60

1 Answers1

0

I got the solution: The problem was I was flushing the already flushed transaction.And thus it was giving me no transaction in progress error along with the one i posted above.So i just removed the getEm().flush(); and getEm().clear(); from the finally block and it started working :)

Hope it will help others..

kirti
  • 4,499
  • 4
  • 31
  • 60