Hi everyone,
My stateless session bean ignores the UserTransaction.rollback(). For each
SQL statement within the UserTransaction.begin() and
UserTransaction.commit()/rollback(), the bean commits each SQL statement
immediately (UserTransaction.rollback() at the end has no effect!) I am
using Postgresql 7.1.1 (jdbc driver compiled from the Postgresql source
code) and JBoss 2.2.1. The following is my code and the deployment
descriptor. Any help will be appreciated. Thanks in advance.
Kobi
Code follows:
package test;
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import java.util.*;
import javax.transaction.*;
import java.sql.*;
public class TestBean implements SessionBean
{
transient protected SessionContext m_ctx = null;
public void testRollback()
{
UserTransaction trans = m_ctx.getUserTransaction();
Connection conn = null;
Statement stmt = null;
try
{
trans.begin();
// get a connection for this transaction context
conn = DriverManager.getConnection(
"jdbc:postgresql://myhost/mydb", "id", "pwd");
// insert a new row.
stmt = conn.createStatement();
int nResult = stmt.executeUpdate("insert into mytable (id, name)
values(1,'Rolledback');");
stmt.close();
conn.close();
trans.rollback();
System.out.println("Rolled back."); //Printed out in the JBoss
cmd.
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
/**
Empty method body
*/
public ContentMgrBean() {}
/**
Empty method body
*/
public void ejbCreate() {}
/**
Empty method body
*/
public void ejbRemove() {}
/**
Empty method body
*/
public void ejbActivate() {}
/**
Empty method body
*/
public void ejbPassivate() {}
/**
Empty method body
*/
public void setSessionContext(SessionContext ctx)
{
m_ctx = ctx;
}
}
The deployment descriptor (ejb-jar.xml):
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar>
<description>jBoss test application </description>
<display-name>Test</display-name>
<enterprise-beans>
<session>
<ejb-name>Test</ejb-name>
<home>test.TestHome</home>
<remote>test.Test</remote>
<ejb-class>test.TestBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<bean-transaction>
<method>
<ejb-name>Test</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
jboss.xml:
<?xml version="1.0" encoding="UTF-8"?>
<jboss>
<enterprise-beans>
<session>
<ejb-name>Test</ejb-name>
<jndi-name>test/Test</jndi-name>
</session>
</enterprise-beans>
</jboss>
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user