[jboss-user] [EJB 3.0] - Roll Back not working
saulat78
do-not-reply at jboss.com
Fri Nov 2 07:36:25 EDT 2007
Hello
I have a Stateless EJB, that is performing two transactions via DAOs,
the first DAO inserts the record, then I am explicitly throwing exception in the second DAO and it fails to add record, then I expect the ut.rollback() method to roll back my first record but it is not doing so, can any one tell me what I am missing.
|
| @Stateless
| @TransactionManagement(TransactionManagementType.BEAN)
| public class DTCTestBean implements DTCTestRemote
| {
| @Resource SessionContext ctx;
|
| public void performTransaction(int param)
| {
|
| UserTransaction ut=null;
| Connection conn = null;
|
| try
| {
| InitialContext initCtx = new InitialContext(getProperties());
| DataSource ds = (javax.sql.DataSource)initCtx.lookup(DAOConstants.DB_VAM);
| conn = ds.getConnection();
| ut = ctx.getUserTransaction();
|
| // start the transaction
| ut.begin();
|
| FirstDAO dao = new FirstDAO();
| MyDTO dto = new MyDTO();
| dto.setA(123);
| int i = dao.insert(dto, conn); //performs the first transaction
|
|
| SecondDAO dao2 = new SecondDAO();
| SecondDTO dto2 = new SecondDTO();
| dto2.setB(456);
|
| int j = dao2.insert(dto2, conn) ; //explicitly throwing exception
|
| ut.commit();
| }
| catch(Exception e)
| {
| try
| {
| System.out.println("Attempting to roll back");
| ut.rollback(); // Y this dont roll back the first transaction
| System.out.println("Transaction roll back");
|
| }
| catch(Exception in)
| {
|
| in.printStackTrace();
| }
|
| }
| finally
| {
| try
| {
| if(conn != null)
| conn.close();
| }
| catch(Exception e)
| {
| System.out.println("Ignorable Exception " + e.toString() );
| }
| }
| }
|
| private Properties getProperties()
| {
| String urlName = "jnp://222.222.2.227:1099";
| Properties p = new Properties();
| p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
| p.put(Context.PROVIDER_URL, urlName);
| p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
| return p;
|
| }
| }
My data source conf is
<datasources>
| <local-tx-datasource>
| <jndi-name>VAM</jndi-name>
| <use-java-context>false</use-java-context>
| <connection-url>jdbc:sqlserver://YCASHMTDEV:1433;databaseName=VAM</connection-url>
| <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
| <user-name>sa</user-name>
| <password>sa1234</password>
|
| <max-pool-size>100</max-pool-size>
| <min-pool-size>10</min-pool-size>
| <blocking-timeout-millis>5000</blocking-timeout-millis>
| <idle-timeout-minutes>15</idle-timeout-minutes>
|
| <!-- correspondinasdg type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
| <metadata>
| <type-mapping>mySQL</type-mapping>
| </metadata>
| <metadata>
| <type-mapping>MS SQLSERVER2005</type-mapping>
| </metadata>
| </local-tx-datasource>
|
|
|
| </datasources>
I am also using two more data sources in the same file but i only included that I am using.
Any help will be appreciated
Saulat
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4101256#4101256
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4101256
More information about the jboss-user
mailing list