Jacob, Thomas et all.

Need your help to catch the
org.apache.ojb.broker.KeyConstraintViolatedException (using OTM API) when
trying to insert an object with a duplicate key (index not accepting dup
keys). The first run is not throwing the LockingException.

We are executing the following code (OTM API):
where aGrabar is a reference to a given object that implementes the
FYSentity interface (a common interface we implement in our persistent
objects).

 private static int inserto(FYSentity aGrabar){
    setConn();  //setups _kit (TestKit) and _conn (OTMConnection)
    try {
      tx = _kit.getTransaction(_conn); // 1. abro transaccion
      tx.begin();
      _conn.makePersistent(aGrabar);
      tx.commit();
      _conn.invalidateAll();
    }
   catch (LockingException e) {
      if (tx.isInProgress()) {
        tx.rollback();
      }
      //throw e;
      return 8; //no puede hacer el lock
    }
   catch (Exception e){  //added to try to intercept
      tx.rollback();     //uncaught exceptions
      e.getStackTrace();
      return 9;
    }
    PersistenceBrokerFactory.releaseAllInstances();
    _conn.close();
    _conn = null;
    return 0;
  }

.



The following stack trace seems to be thrown by core OJB code, not our
catch statements:
org.apache.ojb.broker.KeyConstraintViolatedException: SQL failure while
insert object data for class ar.com.fys.seguridad.UsuarioImpl, PK of the
given object is [ oID=8E8D673B-76A6-DAC6-B5AF-72F71E5CBC15], object was
ar.com.fys.seguridad.Usuario: 8E8D673B-76A6-DAC6-B5AF-72F71E5CBC15,
exception message is [Duplicate key or integrity constraint violation
message from server: "Duplicate entry 'admin' for key 2"] at
org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeInsert(Unknown
Source) at
org.apache.ojb.broker.accesslayer.batch.BatchManagerImpl.executeInsert(Unknown
Source)at
org.apache.ojb.broker.core.PersistenceBrokerImpl.storeToDb(Unknown Source)

        at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown Source)

        at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown Source)

        at org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(Unknown
Source)

        at org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(Unknown
Source)

        at
org.apache.ojb.otm.core.ConcreteEditingContext.checkpointInternal(Unknown
Source)

        at org.apache.ojb.otm.core.ConcreteEditingContext.commit(Unknown Source)

        at org.apache.ojb.otm.core.Transaction.commit(Unknown Source)

        at
ar.com.fys.tagrer.servidor.controlador.ControladorBD.inserto(ControladorBD.java:161)

        at
ar.com.fys.tagrer.servidor.controlador.ControladorBD.grabar(ControladorBD.java:131)

        at
ar.com.fys.tagrer.initSistema.InitSistema.grabaClases(InitSistema.java:128)

        at ar.com.fys.tagrer.initSistema.InitSistema.<init>(InitSistema.java:46)

        at ar.com.fys.tagrer.initSistema.InitSistema.main(InitSistema.java:133)

Caused by: java.sql.SQLException: Duplicate key or integrity constraint
violation message from server: "Duplicate entry 'admin' for key 2"

        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)

        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)

        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)

        at com.mysql.jdbc.Connection.execSQL(Connection.java:2247)

        at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1772)

        at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1619)





*********************************************************
Hi all,

We cannot find a way to properly handle exceptions with duplicate keys
When trying to persist an object with a column indexed not accepting
duplicates usitn OTM.

Weir behaviour if we try to run our code twice in a row:
Stack trace shows in the first run
org.apache.ojb.broker.KeyConstraintViolatedException.

Second run will throw LockingException. We cannot catch this
KeyConstranintVialoatedException when using OTM no matter where we use
catch try statements.

Any ideas out there?

Thanks in advance,
Gustavo.



--------------------------------------------------------------------- To
unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to