Richard Zowalla created OPENJPA-3093:
----------------------------------------
Summary: 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
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)