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

Maxim Solodovnik resolved OPENJPA-3104.
---------------------------------------
    Fix Version/s: 4.3.0
         Assignee: Richard Zowalla
       Resolution: Fixed

> Spurious UPDATE of an unchanged unenhanced instance on flush after a bulk 
> DELETE removed its row
> ------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-3104
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-3104
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 4.2.0
>            Reporter: Richard Zowalla
>            Assignee: Richard Zowalla
>            Priority: Major
>             Fix For: 4.3.0
>
>
> After a JPQL bulk DELETE (or a native DELETE) removes the row of an entity 
> instance that the persistence context still manages, the next flush issues an 
> UPDATE for that instance although it was not modified. The UPDATE hits 0 rows 
> and fails with an OptimisticLockException.
> Reproducer (unenhanced entity, i.e. runtime subclass enhancement, one 
> transaction):
> {noformat}
> em.getTransaction().begin();
> Person p = new Person("a", 1);
> em.persist(p);
> em.flush();                                              // INSERT
> em.createQuery("DELETE FROM Person p WHERE p.name = :n")
>   .setParameter("n", "a").executeUpdate();               // bulk DELETE 
> removes the row
> em.flush();                                              // or any query that 
> triggers a flush
> // -> UPDATE Person SET age = ? WHERE id = ?  -> 0 rows -> 
> OptimisticLockException
> {noformat}
> The instance is unchanged after the first flush, so no UPDATE is expected. 
> Jakarta Persistence does not require the persistence context to be 
> synchronized with bulk deletes, but a spurious dirty update of an unchanged 
> instance should not happen. It reproduces with an IDENTITY id and with an 
> assigned id. It was not seen with build-time or javaagent enhancement, which 
> points at the dirty tracking of unenhanced (subclassed) instances.
> Found while testing Jakarta Data repositories (derived deleteBy methods are 
> JPQL bulk deletes) in Apache TomEE 11 with OpenJPA 4.2.0.



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

Reply via email to