How to manage exception while using Container Managed Transactions?

Solution Unverified - Updated -

Issue

  • Following is the sample EJB code;
...
        try{
            System.out.println("**************  trying to persist  **************");
            _em.persist(atmAdmin);
        }
        catch(Exception e){
            System.out.println("#####################  could not persist to database  ###################");
            e.printStackTrace();
        }
...
  • Below is the datasource details;
...
<datasources>
  <local-tx-datasource>
    <jndi-name>TempDB</jndi-name>
    <use-java-context>true</use-java-context> 
    <connection-url>jdbc:sqlserver://127.0.0.1:1433;DatabaseName=Temp</connection-url>
    <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
    <user-name>test</user-name>
    <password>12345678</password>
    <min-pool-size>10</min-pool-size>
    <max-pool-size>50</max-pool-size>
    <metadata>
        <type-mapping>MS SQLSERVER2000</type-mapping>
    </metadata>
  </local-tx-datasource>
...
  • When the database is down, I don't get the exception in my code and the exception is logged to the server.log probably by hibernate but only after the transaction is committed.

  • How I can control the exception in my code?

Environment

  • Red Hat JBoss EAP

    • 5.x
    • 6.x
  • EJB 3.0

  • Hibernate

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content