You may select "database generated" PK in the Modeler:
http://cayenne.apache.org/doc/generated-columns.html
This works conditional on whether the JDBC driver supports this
feature (not sure about MS Access, but SQLServer and MySQL do)
Andrus
On Jul 23, 2007, at 12:23 PM, mr.abanjo wrote:
> 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 - 07:56:01 EDT