[ 
https://issues.apache.org/jira/browse/OPENJPA-3098?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18149819#comment-18149819
 ] 

ASF subversion and git services commented on OPENJPA-3098:
----------------------------------------------------------

Commit 65e29d44fc5933ffbbc95933ef3740a35ebd86c8 in openjpa's branch 
refs/heads/OPENJPA-3098 from Richard Zowalla
[ https://gitbox.apache.org/repos/asf?p=openjpa.git;h=65e29d44f ]

[OPENJPA-3098] Delete only from the table of the entity in a MySQL and MariaDB 
bulk delete

On MySQL and MariaDB, which require a delete target, a bulk delete whose WHERE
clause joins another table named every table of the select as a target, as in
DELETE t0, t1 FROM BRG_LINE t0 INNER JOIN BRG_ORDER t1 ..., and deleted the
joined rows too. The target is now the alias of the table whose identifier the
select reads. When the statement falls back to the subquery on the primary key,
the target is the table name, and the subquery is wrapped in a derived table
where the database does not allow the target table in a subquery, as the direct
form already does.


> MySQL and MariaDB: bulk DELETE whose WHERE clause uses a relation also 
> deletes the rows of the joined table
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-3098
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-3098
>             Project: OpenJPA
>          Issue Type: Bug
>            Reporter: Richard Zowalla
>            Assignee: Richard Zowalla
>            Priority: Major
>             Fix For: 4.3.0
>
>
> On MySQL and MariaDB a JPQL bulk delete whose WHERE clause navigates a 
> relation deletes the matching rows of the joined table too. For
> {code}
> DELETE FROM BulkRangeLine l WHERE l.order.status = :status
> {code}
> OpenJPA issues
> {code}
> DELETE t0, t1 FROM BRG_LINE t0 INNER JOIN BRG_ORDER t1 ON t0.ORDER_ID = t1.ID 
> WHERE (t1.STATUS = ?)
> {code}
> MySQL's multi-table DELETE removes the rows from every table in the target 
> list, so the orders that match are deleted together with their lines, and 
> executeUpdate() returns the sum (3 instead of 2 in the test).
> AbstractMySQLDictionary sets requiresTargetForDelete, and 
> DBDictionary.getDeleteTargets() lists all table aliases of the select (since 
> OPENJPA-597). Only the table of the entity of the statement must be a target: 
> DELETE t0 FROM BRG_LINE t0 INNER JOIN BRG_ORDER t1 ...
> Found by TestBulkSingleTableRange.deleteLinesByOrderStatus (OPENJPA-3094), 
> which fails on MySQL 8.4/9.7 and MariaDB 10.11/12.3 in the scheduled 
> Databases run: https://github.com/apache/openjpa/actions/runs/45111674759



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to