• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB 3 Stateful BMT SessionBean Open Transaction not behaving properly : JBoss 6 : EJB 3

 
Greenhorn
Posts: 4
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I was experimenting with BMT and StatefulBean in EJB 3 in JBoss 6 server. I am using MySQL as database. The SFSB has two methods. Both the methods are inserting some data in Database. Following is the code for the SFSB:

@Remote(StatefulBMTRemote.class)
@Stateful(name="StatefulBeanBMT")
@Resource(name="jdbc/MySqlDS",
mappedName="java:/MySqlDS", type=javax.sql.DataSource.class)
@TransactionManagement(TransactionManagementType.BEAN)
public class StatefulBMTBean
{

@Resource(name="jdbc/MySqlDS")
private DataSource dbSrc;

private Connection con ;

private Connection con ;


private String userId;
private String password;

private String userName;
private String address;

@Resource private UserTransaction utx;

@PostConstruct
@PostActivate
void initialize()
{
try {
con = dbSrc.getConnection();
} catch (SQLException e) {

}

}

@PreDestroy
@PrePassivate
void release()
{
if(con != null)
{
try {
con.close();
} catch (SQLException e) {

}
con = null;
}

}

public void addUserCredential(String userId, String pwd)
{
try
{
utx.begin();
} catch (NotSupportedException e)
{

} catch (SystemException e)
{

}
this.userId = userId;
this.password = pwd;
try {

Statement stmt = con.createStatement();
String sql = "insert into users (USER_ID, USER_PASSWORD) " +
"values ('" + userId + "','" + password
+ "')";
stmt.executeUpdate(sql);
stmt.close();
} catch (SQLException e) {
try
{
utx.rollback();
} catch (IllegalStateException e1)
{

} catch (SecurityException e1)
{

} catch (SystemException e1)
{

}
}
}

public void addUserDetail(String userName, String address)
{
this.userName = userName;
this.address = address;
try {
Statement stmt = con.createStatement();
String sql = "select max(detail_id) from user_detail";
ResultSet rs = stmt.executeQuery(sql);
int maxId = 0;
if(rs.next())
{
maxId = rs.getInt(1);
}
sql = "insert into user_detail values(" + (++maxId) + ",'" + this.userName
+ "','" + this.address + "')";
stmt.executeUpdate(sql);
rs.close();
stmt.close();

} catch (SQLException e) {
try
{
utx.rollback();
} catch (IllegalStateException e1)
{
} catch (SecurityException e1)
{
} catch (SystemException e1)
{
}
}

}


@Remove
public void cancelAdd()
{
userId = null;
userName = null;
password = null;
address = null;
try
{
utx.rollback();
} catch (IllegalStateException e1)
{
} catch (SecurityException e1)
{
} catch (SystemException e1)
{
}
}

@Remove
public void commit()
{

try
{
utx.commit();

} catch (SecurityException e)
{
} catch (IllegalStateException e)
{
} catch (RollbackException e)
{
} catch (HeuristicMixedException e)
{
} catch (HeuristicRollbackException e)
{
} catch (SystemException e)
{
}

}






The MySQL ds file content is as follows:

<datasources>
<local-tx-datasource>
<jndi-name>MySqlDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/test</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password>root123</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>


I have created table with InnoDB Engine.

From a standalone java client when I am accessing the SFSB I founded that even if I call cancelAdd(), The rollack is not taking place and data is staying in Database. After Stacktrace enabling I found no exception either.


This is driving me mad Because This is one of the advantages of using BMT in SFSB.

Please help.

Thanks in Advance
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic