[
https://issues.apache.org/jira/browse/OPENJPA-3099?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18151933#comment-18151933
]
ASF subversion and git services commented on OPENJPA-3099:
----------------------------------------------------------
Commit 13be6dea5bf9ce11f3455dd5be6e7e837b35062b in openjpa's branch
refs/heads/OPENJPA-3099 from Richard Zowalla
[ https://gitbox.apache.org/repos/asf?p=openjpa.git;h=13be6dea5 ]
[OPENJPA-3099] Join the related entity of TYPE() of a single-valued path
TYPE() of a path such as l.order did not join the table of the related
entity, so the discriminator was read from an unjoined alias: a bulk
delete or update with such a condition changed every row, and a select
returned duplicates or failed with an aggregate. TYPE() now joins the
relation, and a type literal in a condition no longer puts the table of
its entity in the FROM clause. TYPE(x) <> X outside a table-per-class
hierarchy is no longer written as an equality, and SELECT TYPE() of a
path returns the base class for its discriminator value and null for a
missing relation.
> TYPE() of a single-valued path is not joined: bulk DELETE deletes all rows,
> SELECT fails
> -----------------------------------------------------------------------------------------
>
> Key: OPENJPA-3099
> URL: https://issues.apache.org/jira/browse/OPENJPA-3099
> Project: OpenJPA
> Issue Type: Bug
> Reporter: Richard Zowalla
> Assignee: Richard Zowalla
> Priority: Major
> Fix For: 4.3.0
>
>
> TYPE() applied to a relation path adds the table of the related entity to the
> FROM clause without the join condition. With BulkRangeLine -> BulkRangeOrder
> (SINGLE_TABLE, subclass BulkRangeRushOrder), 4 orders of which 2 are rush
> orders, 2 lines each:
> {code}
> DELETE FROM BulkRangeLine l WHERE TYPE(l.order) = BulkRangeRushOrder
> {code}
> issues on Derby
> {code}
> DELETE FROM BRG_LINE WHERE ID IN (SELECT DISTINCT t1.ID FROM BRG_ORDER t0,
> BRG_LINE t1 WHERE (t0.ORDER_TYPE = 'BulkRangeRushOrder'))
> {code}
> The cross join matches every line, so all 8 lines are deleted instead of the
> 4 lines of the rush orders. MySQL produces the same cross join (DELETE t1
> FROM BRG_ORDER t0, BRG_LINE t1 ...).
> The same condition in a SELECT is not joined either and fails on Derby:
> {code}
> SELECT COUNT(l) FROM BulkRangeLine l WHERE TYPE(l.order) = BulkRangeRushOrder
> {code}
> Column reference 'T0.ID' is invalid ... \{SELECT t0.ID, COUNT(t1.ID) FROM
> BRG_ORDER t0, BRG_LINE t1 WHERE (t0.ORDER_TYPE = 'BulkRangeRushOrder')}
> Expected: the path is joined (t1.ORDER_ID = t0.ID), 4 lines are deleted, and
> the count is 4.
> Reproduced on master (86e153ab7) with the entities of
> TestBulkSingleTableRange (OPENJPA-3094); found while working on OPENJPA-3098.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)