Hi. I have the following problem: i'm calling a Session Stateless Bean from a bean. The Session Bean just execute some insert or update statements into a PostgreSQL DB (first it tries to insert a record in the DB, if an exception occurres, it execute an update statement; if another exception occurres, it means that an extra error has been raised, so i need a general rollback). This operation is executed for an undetermined number of times ( generally from 2 to 14, depending on the number of days, but this is not a problem). I want to execute commit() only at the end of all the queries: in this way, if an error occurs, i may execute a general rollback(). Anyway, i encounter the following problem: when i just try to insert record, everything's OK. But if i try to update some values, the first time it seems to be ok( JBoss raises a java.sql.SQLException: ERROR: Cannot insert a duplicate key into unique index consuntivation_pkey), the second time the exception is not raised and it's executed the insert statement , but at the end no commit is executed and values are not modified. I'm in trouble: what's the problem? Maybe the fact that Connection is always open and when i call con.prepareStatement("") all data are lost? Or the fact that Session Bean is Stateless? (I used a Statless Bean 'cause i need to return a Collection and i don't know how to serialize some objects) May someone help me?
The code is: ////////////////// CODE FOR THE BEAN //////////////////////// ............................................ Enumeration e=vactivities.elements(); cs.StartStore(); // it just open the connection which reamains the same for all the while while(e.hasMoreElements()) { myActivityStore m=(myActivityStore)e.nextElement(); /////////////////////////// my own class int insertResult=cs.InsertStoreConsuntivation(m.id,m.idactivity,m.day,m.activityName,m.hours,m.notes); if(insertResult==2) //// an SQLException occurred { int updateResult=cs.UpdateStoreConsuntivation(m.id,m.idactivity,m.day,m.activityName,m.hours,m.notes); if(updateResult==0) { cs.EndStore(false); ////// connection is closed and rollback is invoked return false; } } if(insertResult==0) ///// a different Exception occurred , i need a global commit { cs.EndStore(false); ////// connection is closed and rollback is invoked return false; } } cs.EndStore(true); ///// connection is closed, everything was OK and COMMIT is invoked return true; .............................................................. /////////////////////////////////// SESSION BEAN public int InsertStoreConsuntivation(Integer idr,Integer ida,java.sql.Date day,String activityName,Integer hours,String notes) throws SQLException,RemoteException { System.out.println("InsertStoreConsuntivation called"); PreparedStatement insertStmt=null; try { System.out.println("Get Connection to DB\n"); insertStmt=con.prepareStatement("INSERT INTO \"consuntivation\" VALUES(?,?,?,?,?,?)"); insertStmt.setInt(1,idr.intValue()); insertStmt.setInt(2,ida.intValue()); insertStmt.setDate(3,day); insertStmt.setString(4,activityName); insertStmt.setInt(5,hours.intValue()); insertStmt.setString(6,notes); System.out.println("Just before execution of INSERT Query\n"); int insertEJBResult=insertStmt.executeUpdate(); }catch(SQLException sqle) { System.out.println("SQLException into InsertStoreConsuntivation "+sqle.toString()); insertStmt.close(); return 2; }catch(Exception e) { System.out.println("Exception into InsertStoreConsuntivation "+e.toString()); insertStmt.close(); return 0; } insertStmt.close(); return 1; } public int UpdateStoreConsuntivation(Integer idr,Integer ida,java.sql.Date day,String activityName,Integer hours,String notes) throws SQLException,RemoteException { System.out.println("UpdateStoreConsuntivation called"); PreparedStatement updateStmt=null; try { updateStmt=con.prepareStatement("UPDATE \"consuntivation\" SET hours=?, notes=? "+ " WHERE resource_id=? AND idactivity=? AND day=?"); updateStmt.setInt(1,hours.intValue()); updateStmt.setString(2,notes); updateStmt.setInt(3,idr.intValue()); updateStmt.setInt(4,ida.intValue()); updateStmt.setDate(5,day); System.out.println("Just before execution of UPDATE Query\n"); int updateEJBResult=updateStmt.executeUpdate(); System.out.println("Valore di updateEJBResult "+updateEJBResult); }catch(Exception exc) { System.out.println("Caught Exception in UPDATE "+exc.toString()); System.out.println(" LA TRANSAZIONE VERRĄ ANNULLATA"); updateStmt.close(); return 0; } updateStmt.close(); System.out.println("Chiudo updateStmt"); return 1; } Thank you Federico Vesco _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development