Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Call an EJB after a CMT has been rolled-back  RSS feed

 
Saloon Keeper
Posts: 2406
296
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have servlet calling an EJB (MessageServiceImpl), which calls another EJB (MessageRegistry) that performs a database lookup using JPA.  When there is a JPA failure, an exception is thrown.  I want to catch the exception, and raise an alarm indicating that there was a failure (which fires an SNMP trap), and then have the exception handled normally.  The alarm management is handled by another EJB (ManagementServiceImpl).

The issue that I am having is that after the JPA failure, the transaction associated with this processing has been marked as rolled-back, and the attempt to call the ManagementService EJB, results in an EJBTransactionRolledbackException being thrown (since it normally wouldn't make sense to continue processing if the transaction is over-with).

I could probably use a org.eclipse.persistence.exceptions.ExceptionHandler to catch the failure before the container rolls-back the transaction and raise an alarm there, but there would not be enough information to actually determine what type of application processing was being done (for example - how would it determine the the error was associated with looking up a message from the Message Registry).

Any ideas on what approach might be able to use to be able to call the ManagementService EJB after a JPA failure?

 
Sheriff
Posts: 21638
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't you specify that either class ManagementServiceImpl or method ManagementServiceImpl.raiseAlarm runs either with no transaction (@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)) or a new transaction (@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)?
 
Ron McLeod
Saloon Keeper
Posts: 2406
296
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes - I just finished trying TransactionAttributeType.REQUIRES_NEW, and I was able to raise the alarm.

Now, I am trying to sort-out if I need to manually set the outer transaction to rolled-back or not.

Maybe if I make the raiseAlarm method TransactionAttributeType.NOT_SUPPORTED, I don't need to worry about this.
 
Ron McLeod
Saloon Keeper
Posts: 2406
296
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TransactionAttributeType.NOT_SUPPORTED solves the problem

Thanks Rob.
 
Rob Spoor
Sheriff
Posts: 21638
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!