Andrus Adamchik created CAY-2791:
------------------------------------

             Summary: Unmapped columns are included in INSERT statements
                 Key: CAY-2791
                 URL: https://issues.apache.org/jira/browse/CAY-2791
             Project: Cayenne
          Issue Type: Bug
    Affects Versions: 4.2.RC1
            Reporter: Andrus Adamchik


Columns mapped in DbEntity, but not mapped in ObjEntity are still included in 
the generated INSERT statements because of this:

{noformat}
public InsertBatchQuery(DbEntity entity, int batchCapacity) {
  super(entity, new ArrayList<>(entity.getAttributes()), batchCapacity);
}
{noformat}

This is not a new issue, but this is evil. It inserts explicit NULLs in all 
unmapped columns, which is too big of an assumption to always work.

E.g. I have a case of "calculated" MySQL columns defined like this:
{noformat}
CALC_COLUMN decimal(12,6) GENERATED ALWAYS AS ((COL_A / COL_B)) STORED,
{noformat}

Inserting NULLs in those causes exceptions. The workaround is to use  "exclude 
column" rules in DB Import. 

But the issue itself should be addressed and not require a workaround. We need 
to only insert in the columns that are relevant for the ObjEntity (i.e. those 
mapped to ObjAttributes, pks and fks).





--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to