Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EntityManager lock overrides changes done to a managed entity #2071

Open
vseibt opened this issue Feb 22, 2024 · 0 comments
Open

EntityManager lock overrides changes done to a managed entity #2071

vseibt opened this issue Feb 22, 2024 · 0 comments

Comments

@vseibt
Copy link

vseibt commented Feb 22, 2024

EntityManager lock overrides changes done to a managed entity

If using EntityManager#lock with a managed entity with LockModeType.PESSIMISTIC_WRITE all
previous changes to this managed entity (by merge or setters) are lost.

To Reproduce

Excerpt from test case

            em.getTransaction().begin();
            TestEntityMaster testMaster = em.find(TestEntityMaster.class, ID);
            testMaster.setName("new name");
            em.lock(testMaster, LockModeType.PESSIMISTIC_WRITE);
            assertEquals("new name", testMaster.getName());
            em.getTransaction().commit();

Assertion fails.

  • EclipseLink version 4.0.2
  • Java/JDK version 17

Expected behavior
Lock should not override content already changed in the managed entity (assertion in above code should not fail).

Additional context
See class TestBug.java in branch "bug-entitymanager-lock" in repository git@github.com:vseibt/eclipselink-jpa-testcase-202402.git

Note
Test project in the above repo was created using
mvn archetype:generate -DarchetypeGroupId=org.eclipse.persistence -DarchetypeArtifactId=org.eclipse.persistence.bug.jpa-archetype -DarchetypeVersion=5.0.0-SNAPSHOT -DgroupId=eclipselink.bug.testcase -DartifactId=jpa-testcase

like suggested.

Unfortunately current version of this plugin does not have parameters for groupId and artifactId, leading to group id and artifact id from the archetype being used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant