[
https://issues.apache.org/jira/browse/OPENJPA-3093?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18148316#comment-18148316
]
ASF subversion and git services commented on OPENJPA-3093:
----------------------------------------------------------
Commit fdb972e67a9bd65ab9664286cf668a35bf0cd922 in openjpa's branch
refs/heads/OPENJPA-3093 from Richard Zowalla
[ https://gitbox.apache.org/repos/asf?p=openjpa.git;h=fdb972e67 ]
[OPENJPA-3093] Do not load lazy to-one relations of a removed entity to order
delete statements
When the relation field is not loaded but the id of the related object was
read with the row, look up the related object in the context cache instead of
loading the field. A related object can only be deleted in the same flush if
it is managed. If the cached instance under that id is a new instance that
replaces a deleted one, load the field as before so the delete row references
the deleted instance.
> Removing an entity loads its lazy to-one relations
> --------------------------------------------------
>
> Key: OPENJPA-3093
> URL: https://issues.apache.org/jira/browse/OPENJPA-3093
> Project: OpenJPA
> Issue Type: Bug
> Reporter: Richard Zowalla
> Assignee: Richard Zowalla
> Priority: Major
> Fix For: 4.3.0
>
>
> When an entity is removed, RelationFieldStrategy.delete() calls
> fetchObjectField() for each to-one relation to set the foreign key on the
> delete row, which is used to order the DELETE statements. For an unloaded
> LAZY relation this loads the related entity, so removing N entities runs up
> to N extra SELECTs per relation, even though the relation is neither cascaded
> nor needed beyond its foreign key value.
> Example (PurchaseOrder with @ManyToOne(fetch = LAZY) customer, OrderLine with
> @ManyToOne(fetch = LAZY) product, PurchaseOrder.lines with cascade ALL):
> removing loaded orders runs
> {noformat}
> SELECT ... FROM PRODUCT t0 WHERE t0.ID = ?
> SELECT ... FROM CUSTOMER t0 WHERE t0.ID = ?
> {noformat}
> for each line and order before the DELETE statements. Hibernate and
> EclipseLink only run the DELETE statements.
> For an unloaded relation, take the foreign key value that is already held for
> the field and look up the related instance in the persistence context instead
> of loading it.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)