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

Thread: bean id specific tx:advice

  1. #11
    Join Date
    Jan 2008
    Location
    San Diego
    Posts
    780

    Default

    If you want to fail or commit on each iteration, the iteration loop needs to be outside of the transaction, the logic in the iteration needs to be wrapped in the transaction, e.g.

    Code:
    while(true)
    {
        // start new transaction    
        dao1.doStuff();
        dao2.doStuff();
        // end transaction
    }
    This is tricky because transactional proxies and annotations don't work when you call a method on the same object, they only work when you are entering the object.

    What this means is that the method that does the work needs to be in another object than the method that runs the loop so you can apply the proxy to the work and not the loop.

    Code:
    public class Looper
    {
        private Worker worker;
        public void setWorker(Worker worker)
        {
            this.worker = worker;
        }
       
        public void loop()
        {
            while (true)
            { 
                try
                {
                    worker.work();
                }
                catch(Throwable t){// ignore or log}
            }
        }
    }
    
    public interface Worker
    {
        public void work();
    }
    
    public class WorkerImpl implements Worker
    {
        private Dao dao1;
        private Dao dao2;
    
        // Setters elided
     
        @Transactional(propagation=Propagation.REQUIRES_NEW
                             rollbackFor=DaoException.class)
        public void work()
        {
            dao1.doStuff();
            dao2.doStuff();
        }
    }

  2. #12
    Join Date
    Oct 2008
    Posts
    5

    Default

    I really, don't know, where I am going wrong.
    I created a class having my method with all the required dao calls and made as an aspect. calling the same method in another class. But still it is not doing the rollback. It is ignoring the failed one and going forward.
    My daos are using hibernate. does this a bottleneck?

  3. #13
    Join Date
    Jan 2008
    Location
    San Diego
    Posts
    780

    Default

    Quote Originally Posted by springTek View Post
    I really, don't know, where I am going wrong.
    I created a class having my method with all the required dao calls and made as an aspect. calling the same method in another class. But still it is not doing the rollback. It is ignoring the failed one and going forward.
    My daos are using hibernate. does this a bottleneck?
    Is the exception that you are throwing a subclass of RuntimeException?

  4. #14
    Join Date
    Oct 2008
    Posts
    5

    Default

    Yes. my appexception is a subclass of Runtime Exception.

  5. #15
    Join Date
    Apr 2008
    Location
    Lomma, Sweden
    Posts
    41

    Default

    please supply sourcecode and appcontext.

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
  •