[ 
https://issues.apache.org/jira/browse/CAY-2791?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Andrus Adamchik updated CAY-2791:
---------------------------------
    Description: 
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. Inserting NULLs in those causes 
exceptions. 
{noformat}
CALC_COLUMN decimal(12,6) GENERATED ALWAYS AS ((COL_A / COL_B)) STORED,
{noformat}

The workaround for me was to use  "exclude column" rules in DB Import. But the 
issue should still 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).



  was:
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. Inserting NULLs in those causes 
exceptions. 
{noformat}
CALC_COLUMN decimal(12,6) GENERATED ALWAYS AS ((COL_A / COL_B)) STORED,
{noformat}

The workaround is to use  "exclude column" rules in DB Import. But the issue 
should still 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).




> 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
>            Priority: Major
>
> 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. Inserting NULLs in those causes 
> exceptions. 
> {noformat}
> CALC_COLUMN decimal(12,6) GENERATED ALWAYS AS ((COL_A / COL_B)) STORED,
> {noformat}
> The workaround for me was to use  "exclude column" rules in DB Import. But 
> the issue should still 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