Info wrote:

Hello,

I am using following code to update a record:

broker = PersistenceBrokerFactory.defaultPersistenceBroker();
QueryByCriteria query = new QueryByCriteria(department);
DepartmentDto result = (DepartmentDto) broker.getObjectByQuery(query);
if (result != null){
result.setDescription(department.getDescription());
result.setName(department.getName());
broker.beginTransaction();
broker.store(result);
broker.commitTransaction();
} but I get Exception:


*org.apache.ojb.broker.PersistenceBrokerSQLException: SQL failure while insert object data for class com.zousys.silique.dto.DepartmentDto, PK of the given object is [ departmentId=0], object was [EMAIL PROTECTED], exception message is [Invalid argument value, message from server: "Duplicate entry '0' for key 1"]

*From online document, I read that OJB will check if the PK exist, if yes, OJB will update the record. Anyone know why I get this error?


Did you set autoincrement="true" in the field-descriptor of all PK fields in com.zousys.silique.dto.DepartmentDto?


<field-descriptor
         name="id"
         column="SM_ID"
         jdbc-type="INTEGER"
         primarykey="true"
         autoincrement="true"
        />

As a side-note if possible don't use primitive types for PK and FK fields to avoid "0"/"null" problems (OJB assume that the primitive 0
represents "null") or never use value 0 for PK or FK fields and start with values >0 (OJB sequence manager do this by default).


regards,
Armin

Thanks a lot!

Wallace

---------------------------------------------------------------------
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