-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Solved: Rollback of transaction
PostPosted: Sun May 31, 2009 2:26 pm 
Newbie

Joined: Sun May 31, 2009 2:12 pm
Posts: 4
Hi,

I have problem with rollbacking the transaction.

I create an application which create a record in table (entity) Application.

Code:
    public void createApplication(EntityManager em, Application application) throws ApplicationServiceException {
        log.info("transaction status: " + em.getTransaction().isActive());
        try {
           
            if (application.getApplicationUser() == null) {
                application.setApplicationUser(SecurityHolder.getInstance().getLoggedUser());
            }
            em.persist(application);

            addModulesToApplication(em, application);
        } catch (Exception e) {
            throw new ApplicationServiceException(e);
        }
    }


In this transaction an exception is throw in method addModulesToApplication. The ApplicationServiceException is catched and an entityManager.getTransaction().rollback() is called. But the instance of Application is still in database.

Immediately after calling em.persist(application) is in log SQL Insert. The transaction is active before em.persist(application).

I don't know, why is the insert performed and why after rollback the database still contains the instance.

Btw: I'm using Swing application, I using one entity manager for the one application. On other actions the immediately SQL insert is not performed.

Thanks Mila


Last edited by mvlach on Thu Jun 04, 2009 4:57 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Rollback of transaction
PostPosted: Mon Jun 01, 2009 8:18 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
Can I know how you begin the transaction. Maybe you could post the code for starting the transaction. Also, check if it is because of autocomit true set somewhere in your code. I have not used spring before... but these are the only things i could think of now

_________________
Sukirtha


Top
 Profile  
 
 Post subject: Re: Rollback of transaction
PostPosted: Mon Jun 01, 2009 10:07 am 
Newbie

Joined: Sun May 31, 2009 2:12 pm
Posts: 4
Hi,

thanks for answering.

The entityManager is created throught this code:

Code:
    static {
        emf = Persistence.createEntityManagerFactory("aaaPU");
        em = emf.createEntityManager();
        em.setFlushMode(FlushModeType.COMMIT);
    }

    /**
     * @return the entityManager
     */
    public static EntityManager getEntityManager() {
        return em;
    }


The problem is that in other places in application the transaction works good.

Thanks in advance.

Mila


Top
 Profile  
 
 Post subject: Re: Rollback of transaction
PostPosted: Wed Jun 03, 2009 10:22 am 
Newbie

Joined: Sun May 31, 2009 2:12 pm
Posts: 4
Hi, this is log from the mysql.log.


Code:
090603 16:21:37        99 Query       SET autocommit=0
090603 16:21:44        99 Query       insert into Application (applicant, applicationUser_id, atc, created, deleted, description, inn, lastWave, name, procedureNumber, procedureType, rmsCountry_id, sequenceType, version) values ('12341234', 1, '1234', '2009-06-03 16:21:37', 0, null, '1234', 0, 'asdf', 'asdf', 'DCP', null, 'CROSS_APPLICATION', 0)
           99 Query       select template0_.id as id13_, template0_.moduleType as moduleType13_, template0_.procedureType as procedur3_13_, template0_.templateNode_id as template5_13_, template0_.version as version13_ from Template template0_ where template0_.moduleType='MODULE1' and template0_.procedureType='MRP' limit 2
090603 16:21:46        99 Query       rollback


Top
 Profile  
 
 Post subject: Re: Rollback of transaction
PostPosted: Thu Jun 04, 2009 4:57 am 
Newbie

Joined: Sun May 31, 2009 2:12 pm
Posts: 4
Solved.

The problem was in mysql, especially in myIssam table. Changing to the InnoDB will enable correct behaviour of transaction.

M.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.