Autogenerated column by DB

From: mr.abanjo (mr.abanj..mail.com)
Date: Mon Jul 23 2007 - 05:23:53 EDT

  • Next message: Jack O'Connor: "counting rows"

    Hi,
    sometimes, i must insert or update records in a table that has
    auto-generated column (es: MS Access --> counter)
    When i need to save data, first i check if i already have an object that
    matck the key that come from user (maybe he has insert it manually, or maybe
    is auto-generated.. so i have a null value from the form):

          dtOb = DataObjectUtils.objectForPK(dataContext, entity, compoundKey);

    If the key is not specified by user, the "compoundKey" is null, and the code
    above return also a null DataObject.

    Now i know that is the time to create a new record:

        dtOb = dataContext.createAndRegisterNewObject(entity);

    then, i insert all required values:
       dtOb.writeProperty(....)

     ... BUT NOT the auto-generated column.

    When i perform a commit, Cayenne return me an error, because in the
    generated INSERT query, is still present the auto-generated column, and the
    value assigned is NULL.

    How i can tell to cayenne to ignore the column, in way that the generated
    INSERT query doesn't contains it?
    There are other ways to manage this kind of operation?

    Thanks
    D.



    This archive was generated by hypermail 2.0.0 : Mon Jul 23 2007 - 05:24:20 EDT