Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: transaction roll back not happening after calling flush

  1. #11
    Join Date
    Oct 2009
    Posts
    6

    Default

    middletier and Data access layer both have interfaces as @Transactional with all default attributes.

  2. #12
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Only your service layer should have @Transactional, try removing it from the persistence layer. If my guess is right you probably will now get exceptions that there is no ongoing transaction (due to the @Transactional on the service layer being ignored).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #13
    Join Date
    Oct 2009
    Posts
    6

    Default

    Ok, As you said i removed @Transactional from data access layer.
    I ran my test case but still the same issue. I did not get the exception- no ongoing transaction.
    I guess since data access layer is accessed from middle tier and i invoke midlde tier first which basically starts the transaction. The issue still being i could see data inserted into db even after I throw RuntimeException in middletier as the last step.

  4. #14
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    There really must be something wrong with either your whole setup or your testcase. There can only be data in the database if there is a commit, a commit is generated after a method with @Transactional has ended (depending on the configuration). Even if you call flush you can still rollback those changes a flush isn't a commit.

    Can you strip down a working (well non-working) zip it and put it here (or if you like I can pm you my email).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #15
    Join Date
    Jun 2013
    Posts
    2

    Default

    Has anyone encountered a similar issue? Changes are not rollbacked after flush is called.

    Method is transactional, transaction boundary is defined using AOP transaction advice.

    In my case flush executes 3 DML statements (1 insert, 2 updates), last update fails due exception from DB trigger. Tried to catch exception and clear & close session, that didn't helped.

    Code:
            if (true) {
            	//throw new BatchJobException("Testing rollback"); -- this works and all changes are rollbacked
            	try {
            		sessionFactory.getCurrentSession().flush();
            	} catch (Exception e) {
            		sessionFactory.getCurrentSession().clear();
            		sessionFactory.getCurrentSession().close();
            		throw new BatchJobException("Testing rollback");  -- changes are not rollbacked
            	}
            }
    Last edited by maris; Jun 18th, 2013 at 10:01 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •