• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can a MailSender participate in a transaction?

 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I would like for my mailAbonne method to be fully transactional. I noticed that even on a MailException being thrown the data is persisted by the dao (dao.persistMailingAbonnee(ma);). What's wrong with my configuration?
Can anyone please help?
Thanks in advance,
Julien.





 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Um, because you catch MailException, it will never throw MailException out of that method for the TransactionManager to roll it back.

If you catch it, you must re throw it if you want to release it out of the catch.

Mark
 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:Um, because you catch MailException, it will never throw MailException out of that method for the TransactionManager to roll it back.

If you catch it, you must re throw it if you want to release it out of the catch.

Mark


Good point! I should have spotted that. However when I remove the try/catch the exception is no longer thrown... Any idea why?
regards,
J.
 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Mark,
I changed my method to public as you advised. Here is how it looks now:

I get the same behavior as before...
Any other idea?
J.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have a

<tx:annotation-driven/> tag in your configuration to tell Spring you are using the @Transactional annotations and therefore Spring will create a Proxy around your object to add Transactionlity to it?

Thanks

Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OH, and that method is in your interface that that class implements?

Mark
 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:OH, and that method is in your interface that that class implements?

Mark


Yes it is indeed.
 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:Do you have a

<tx:annotation-driven/> tag in your configuration to tell Spring you are using the @Transactional annotations and therefore Spring will create a Proxy around your object to add Transactionlity to it?

Thanks

Mark


Yes it is too.
 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem seems to be that the timeout is set to indefinitely on my mailsender although I tried to set it to 1 second as follows:

and so the method hangs indefinitely. Hence the rollback is not performed...
Anyone any other idea how to sort this out?
Regards,
J.
 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry it does time out but the method still hangs indefinitely. Here is what the log says:


ERROR [18:13:24,990] (DesktopService.java:171) - org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.wanadoo.fr, port: 25;
nested exception is:
java.net.SocketTimeoutException: connect timed out. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.wanadoo.fr, port: 25;
nested exception is:
java.net.SocketTimeoutException: connect timed out; message exceptions (1) are:
Failed message 1: javax.mail.MessagingException: Could not connect to SMTP host: smtp.wanadoo.fr, port: 25;
nested exception is:
java.net.SocketTimeoutException: connect timed out


Why then won't it roll back the transaction??
Regards,
Julien.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So it is throwing a MailSendException

But that isn't the Exception you are catching, unless MailSendException is a subclass of the Exception type that you are catching.

Mark
 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,

I managed to isolate the problem. I now know it has nothing to do with the java mail api.

Here is my method:


I deliberately throw a RuntimeException from the envoyerMail method and it hangs where it is noted //here. I also know that Spring does create the beans properly and advises them propertly according to the @Transactional annotation because it says so in the logs. It is as if my method wouldn't manage to rethow the RuntimeException...
What could I be getting wrong?
Julien.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try

 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark,
I tried as you advised. Same behaviour as before...

I don't know if that is relevant but here is how my method is called:






Please let me know if the fact that my bean is called from a swingworker matters or not.

Regards,
Julien.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic