Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It seems that there is nothing wrong with <code>flush()</code> after all. The problem was that I didn't set up the data source correctly in JBoss. The lesson here is that if you want to use container managed transactions in EBJs then you need to:</p> <ul> <li>In JBoss, check the <strong>Use JTA?</strong> check box in the data source configuration.</li> <li>In Weblogic, check the <strong>Supports Global Transactions</strong> check box in the Transactions tab of the data source configuration.</li> </ul> <p>Additionally, and in order to clear any confusion, the transaction management in my code is correct. Throwing a <code>RuntimeException</code> <strong>does</strong> rollback the Exception. Why is that? Well, <a href="http://docs.oracle.com/javaee/6/tutorial/doc/bncij.html" rel="noreferrer">from the Java EE 6</a> tutorial we have:</p> <blockquote> <p>if a system exception is thrown, the container will automatically roll back the transaction.</p> </blockquote> <p>But what is a system exception? The tutorial does not seem to touch upon the subject any further, so lets search the <a href="http://jcp.org/aboutJava/communityprocess/final/jsr318/" rel="noreferrer">EJB spec</a>. In page 382 we have:</p> <blockquote> <p>A system exception is an exception that is a java.rmi.RemoteException (or one of its sub- classes) or a RuntimeException that is not an application exception.</p> </blockquote> <p>OK, so maybe the RuntimeException is an application exception then? No it is not, because in page 380 we have this:</p> <blockquote> <p>Application exceptions that are checked exceptions may be defined as such by being listed in the throws clauses of the methods of the bean’s business interface, no-interface view, home interface, component interface, and web service endpoint. An application exception that is an unchecked exception is defined as an application exception by annotating it with the ApplicationException metadata annotation, or denoting it in the deployment descriptor with the application-exception element.</p> </blockquote> <p>So, because I didn't do any of the things listed above, the exception I throw in my code is indeed a system exception and indeed rolls back the transaction <strong>if you have set up your data source to use JTA</strong>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload