Announcement Announcement Module
Collapse
No announcement yet.
ProccessListener (@AfterProcess) + @Transactional doesn't work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ProccessListener (@AfterProcess) + @Transactional doesn't work

    Hello.

    I'm creating a job with Spring Batch 2.1.0 and JPA + JpaTransactionManager, but the @Transactional doesn't work in a Spring Batch Listener (@AfterProcess).

    My use case is:

    1. Get entity from a db using JpaPagingItemReader. (ItemReader)
    2. Map the entity to another object. (ItemProcessor)
    3. Update the state of entity obtained by JpaPagingItemReader. (A listener with a method with @AfterProcess)
    4. Write in a FlatFile. (ItemWriter)

    I'd like to know why @Transactional doesn't work in a spring batch listener.

    some code:

    Code:
           @AfterProcess
           @Transactional
    	public void afterProcess(DCC dcc, DCCRegistry registry) {
    		dcc = dccRepository.findById(dcc.getId());
    		dcc.removeStatus(new Status(null, DCCStatus.SENT));
    	}
    in dcc.removeStatus have some logic to drop a Status entity of database.
    It doesn't work.

    Code:
            @Override
    	@Transactional
    	public DCCRegistry process(DCC dcc) throws Exception {
                    dcc = dccRepository.findById(dcc.getId());
    		dcc.removeStatus(new Status(null, DCCStatus.SENT));
           }
    In a ItemProcessor it works.

    Any ideas?

    Thank you.

  • #2
    I need to use the same approach in a @OnSkipInWrite, so putting the code in ItemProcessor don't solve my problem.
    '
    Thanks again!
    Last edited by hgflima@gmail.com; Feb 11th, 2010, 10:39 AM.

    Comment


    • #3
      The problem is that the listener method is not implementing any interface and the transactional proxy needs an interface (by default). You can fix it by implementing ItemProcessListener or possibly by using proxy-target-class=true in your transaction config.
      Last edited by Dave Syer; Feb 19th, 2010, 11:17 AM. Reason: typo

      Comment

      Working...
      X