This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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

 
Saloon Keeper
Posts: 2260
289
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: 21553
100
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: 2260
289
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: 2260
289
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: 21553
100
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Lasagna is spaghetti flvored cake. Just like this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!