Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Illegal operation exception while trying rollback..

 
Rambo Rambabu
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am developing some session beans with WSAD4.0 , JDBC for OracleThin(classes12.zip), Oracle 8.05. In one of the session bean, I am trying to use callablestatement for updating a table. I am getting an error. When I try the same statmenet directly in SQL, I get an exception saying ORA-01031: insufficient privileges. I need to know how to xlate this actual Oracle exception to the end user to give a proper message.
I am getting this Illegal operation exception from WSAD..
java.lang.IllegalStateException: Illegal operation: tried to commit connection in global tran
exception while I am doing a rollback.
here is my sample code:
updateemployee(string param_passcode){
Connection con = null;
CallableStatement updateEmployee = null;
String sql="";
int noOfRowsUpdated = 0;
Vector works = new Vector();
Employee employee = new Employee();
try
{
con = com.ameritech.pa.common.Util.getConnection();

sql = "BEGIN "+
"UPDATE employee "+
"SET effective_start_date = to_date(?,'MM/DD/YYYY') ,"+
"update_user_id = ?, "+
"update_datetime = SYSDATE "+
"WHERE passcode = ? "+
"AND effective_start_date = TO_DATE(?,'MM/DD/YYYY') ;"+
"END; " ;

System.out.println("The sql is " + sql);

updateEmployee = con.prepareCall(sql);

updateEmployee.setString(1, param_newEffectiveStartDate);
updateEmployee.setString(2, param_loggedInPasscode);
updateEmployee.setString(3, param_passcode);
updateEmployee.setString(4, param_oldEffectiveStartDate);

noOfRowsUpdated = updateEmployee.executeUpdate();

System.out.println("no of rows updated :" + noOfRowsUpdated);
if (noOfRowsUpdated == 0)
{
con.rollback();
return 1;
}
else
{
con.commit();
return 0;
}
}
catch (SQLException s)
{
s.printStackTrace();
}

catch (Exception e)
{
e.printStackTrace();
}

finally
{
try
{
if (updateEmployee != null) updateEmployee.close();
if (con != null) con.close();
}
catch (SQLException se){}
}
return 0;
}
thank You.
 
John Carnell
Author
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rambo Rambabu:
Hi,

I am developing some session beans with WSAD4.0 , JDBC for OracleThin(classes12.zip), Oracle 8.05. In one of the session bean, I am trying to use callablestatement for updating a table. I am getting an error. When I try the same statmenet directly in SQL, I get an exception saying ORA-01031: insufficient privileges. I need to know how to xlate this actual Oracle exception to the end user to give a proper message.
I am getting this Illegal operation exception from WSAD..
java.lang.IllegalStateException: Illegal operation: tried to commit connection in global tran

Hi,
Are you using container manager or bean managed transactions for your session EJB. If you are using container managed transactions (by declaring them in the EJB deployment descriptor) you will get the above exception because the container is responsible for managing the transaction. You should not be trying to commit or rollback() on the connection in CMT-based session beans. Instead, you should let the container manage the transaction. If you want to signal a rollback in a CMT transaction then issue a setRollBack call on the EJB's context object.
I hope that helps.
Thanks,
John
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic