How to manage exception while using Container Managed Transactions?
Issue
- Following is the sample
EJBcode;
...
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
datasourcedetails;
...
<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.logprobably byhibernatebut 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.