Bug 560898 - lock type OPTIMISTIC_FORCE_INCREMENT does not work after flush
Summary: lock type OPTIMISTIC_FORCE_INCREMENT does not work after flush
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 10
: P3 normal with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-08 16:40 EDT by gabriele CLA
Modified: 2022-06-09 10:05 EDT (History)
0 users

See Also:


Attachments
Junit Test (4.99 KB, application/x-zip-compressed)
2020-03-08 16:40 EDT, gabriele CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description gabriele CLA 2020-03-08 16:40:18 EDT
Created attachment 282044 [details]
Junit Test

I have to increase the version of the Parent entity when updating/removing a child Entity
I have two entities: Parent and Child 
The Child entity contains the reference to the Parent entity.

public class Parent {
@Id
private String id;
@OneToMany(cascade = { CascadeType.ALL }, mappedBy = "parent")
private Set<Child> children;
....
}

public class Child {
@Id
private String id;
@ManyToOne(cascade = { CascadeType.ALL })
@JoinColumns({ @JoinColumn(name = "parent_fk", referencedColumnName = "id") })
private Parent parent;
}

I remove all the children of a given parent and then force the update version of the parent entity.
This does not work if, before doing the look, an flush is performed.

Example:
        flush = true
        em.getTransaction().begin();
        Parent p = em.find(Parent.class, PARENT_ID);
        Set<Child> children = p.getChildren();
        assertEquals(3, children.size());
        Child c = em.find(Child.class, "child1");
        children.remove(c);
        if (flush) {
            em.flush();
        }
        p = em.merge(p);
        em.lock(p, LockModeType.OPTIMISTIC_FORCE_INCREMENT);
        em.getTransaction().commit();
        p = em.find(Parent.class, PARENT_ID);
        assertEquals(2, children.size());
        assertEquals(2, p.getUpdateVersion());
Comment 1 Eclipse Webmaster CLA 2022-06-09 10:05:43 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink