You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Sebastian <no...@gmx.net> on 2004/05/19 20:09:30 UTC

MySQL + Native Autoincrement

Hi,
I'm trying to create a record on a table where an autoincrement for the 
id column is performed by the database. Whatever I do I always get:

org.apache.ojb.broker.KeyConstraintViolatedException: SQL failure while 
insert object data for class EnrollmentAction, PK of the given object is 
[ id=0], object was EnrollmentAction@12d96f2, exception message is 
[Duplicate key or integrity constraint violation,  message from server: 
"Duplicate entry '0' for key 1"]
  at 
org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeInsert(JdbcAccessImpl.java:238)
  at 
org.apache.ojb.broker.core.PersistenceBrokerImpl.storeToDb(PersistenceBrokerImpl.java:1620)
  at 
org.apache.ojb.broker.core.PersistenceBrokerImpl.store(PersistenceBrokerImpl.java:1537)
  at 
org.apache.ojb.broker.core.PersistenceBrokerImpl.store(PersistenceBrokerImpl.java:683)
  at 
org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(DelegatingPersistenceBroker.java:174)
  at 
org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(DelegatingPersistenceBroker.java:174)
  at Integrator.main(LmsIntegrator.java:47)
Caused by: java.sql.SQLException: Duplicate key or integrity constraint 
violation,  message from server: "Duplicate entry '0' for key 1"
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1962)
  at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1163)
  at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1257)
  at com.mysql.jdbc.Connection.execSQL(Connection.java:2242)
  at 
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1677)
  at 
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1524)
  at 
org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeInsert(JdbcAccessImpl.java:197)
... 6 more

======================================================

Here is the id field descriptor I'm using:

<class-descriptor class="EnrollmentAction" table="ENROLLMENTS">
  <field-descriptor
   name="id"
   column="id"
   jdbc-type="BIGINT"
   primarykey="true"
   nullable="false"
   access="readonly"
  >
  </field-descriptor>

   ...

</class-descriptor>

======================================================

The sequence-manager is set to 
org.apache.ojb.broker.util.sequence.SequenceManagerNativeImpl

How can I suppress that OJB tries to set ID to 0 in the SQL INSERT 
statement?

Thanks in advance!


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org