0

Using

  • Java 1.6
  • JBoss AS 7.1.1
  • EclipseLink 2.4.1
  • JTA

Updated Question

How do I suppress the stacktrace being thrown by JBoss when I handle the error on my own in a try catch with flush?

Question

I'm trying to persist a entity using em.persist(entity). If no database constraints are being violated everything works fine. But if persisting the entity violates a unique constraints exceptions are thrown. I'm using transactions handled by JBoss so the exception is thrown from another thread.

I've already figured out that I can handle these exceptions globally by setting eclipselink.exception-handler in persistence.xml.

My question is how do I catch and handle these exceptions locally?

maGo
  • 362
  • 1
  • 3
  • 11

1 Answers1

1

Calling em.flush() forces the statements to the database immediately and can be wrapped in a try catch block to handle exceptions before the commit occurs, though most persistence exceptions will mark the transaction for rollback anyway.

Chris
  • 20,138
  • 2
  • 29
  • 43
  • That is true, flush() makes the Exception being thrown and catched right away. But I still get big stacktraces logged by packages `com.arjuna.ats.arjuna` and `org.jboss.ejb3.invocation`. How do I stop this? – maGo Dec 12 '12 at 14:06