1 Reply Latest reply on Feb 18, 2003 5:00 AM by Koen Maes

    castor JDO + transaction problem

    Koen Maes Newbie

      Hi,

      I got JBOSS 3.0.4 + latest castor-0.9.4.3... and the setup like the infamous "rooms2.zip" seems ok except for updates.
      I always run into "Unable to commit" problem.

      have a look at following simple example :

      ** READING FROM THE DATABASE WORKS FINE:

      * @ejb.interface-method
      * view-type="both"
      * @ejb.transaction
      * type="Required"
      *
      public Contact getContact(long contactId) throws ServerException{
      Contact contact = null;
      DataObjects _jdo;
      Database db = null;
      OQLQuery findOql;
      QueryResults results;
      Object data = null;
      try {
      InitialContext ic = new InitialContext();
      _jdo = (DataObjects) ic.lookup("java:/jdo/CastorJDO");
      db = _jdo.getDatabase();
      findOql = db.getOQLQuery("Select c from be.domainnames.J2EEtest1.castor.Contact c where contactId = 81");
      results=findOql.execute();
      if ( results.hasMore() ) {
      contact = (Contact)results.next();
      }
      } catch(Exception e){
      System.err.println(e.getMessage());
      e.printStackTrace();
      }
      finally {
      try{
      if(db!=null) db.close();
      } catch(PersistenceException e) {
      System.err.println("Could not close a database connection:"+e.getMessage());
      e.printStackTrace(System.err);
      }
      }
      return contact;
      }

      ** UPDATING THE DATABASE DOES NOT WORK ??

      * @ejb.interface-method
      * view-type="both"
      * @ejb.transaction
      * type="Required"
      *
      public void updateContact(Contact contact) throws ServerException{
      DataObjects _jdo;
      Database db = null;
      OQLQuery findOql;
      QueryResults results;
      Object data = null;
      try {
      InitialContext ic = new InitialContext();
      _jdo = (DataObjects) ic.lookup("java:/jdo/CastorJDO");
      db = _jdo.getDatabase();
      db.update(contact);
      } catch(Exception e){
      System.out.println("ERROR UPDATING");
      e.printStackTrace();
      }
      finally {
      try{
      if(db!=null) db.close();
      } catch(PersistenceException e) {
      System.err.println("Could not close a database connection:"+e.getMessage());
      }
      }
      }
      Then I always get :

      12:17:40,868 ERROR [STDERR] java.lang.reflect.UndeclaredThrowableException
      12:17:40,869 ERROR [STDERR] at $Proxy81.updateContact(Unknown Source)
      ................................
      12:17:40,884 ERROR [STDERR] Caused by: javax.transaction.RollbackException: Unable to commit, tx=XidImpl [FormatId=257, GlobalId=barabas//67, BranchQual=] status=STATUS_ROLLEDBACK
      12:17:40,885 ERROR [STDERR] at org.jboss.tm.TxCapsule.commit(TxCapsule.java:425)
      12:17:40,885 ERROR [STDERR] at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:73)
      12:17:40,885 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:201)
      12:17:40,886 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:60)


      I am using MSSQL 2000 with the latest MS SQL drivers :


      Manually starting a transaction naturally says the transaction is already in progress.
      I have no more clues............ any help very much appreciated.

      brgds,

      koen

        • 1. Re: castor JDO + transaction problem
          Koen Maes Newbie

          HI again,


          Sorry for putting so much pressure on my issue but I am wondering:
          * did I ask a stupid question ?
          * did I not provide sufficient information ?
          * Or simply nobody ever experienced this problem before ?

          I would greatly appreciate any direction to start digging into my problem but I have no idea where to start...

          I will restate my problem again:
          - I have a Stateless Session Bean that uses CASTOR for persisting data
          - I call the functions in my SLSB from my servlets
          - The functions for reading from the database work fine
          - Updates to the database give ROLLBACKEXCEPTION: UNABLE TO COMMIT

          Maybe some more basic question can be answered :
          * Is this problem CASTOR related or merely JBOSS related ?
          * Or maybe it only has to do with my datasource which might be setup incorrectly ?
          * Which component decides wether it is possible to COMMIT or NOT ?

          **ANY** suggestions very welcome !!

          Many many thx,

          koen