Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 341478

Summary: setLockMode(LockModeType.PESSIMISTIC_READ) on an EntityManager does not result in a select for update
Product: z_Archived Reporter: Missing name Mising name <paul.carter-brown>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P2 CC: taiki.th, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: other   
Whiteboard:

Description Missing name Mising name CLA 2011-03-31 09:10:41 EDT
Build Identifier: 2.0.1.v20100213-r6600

The following code does a join on 2 tables and tries to get an entity object returned that is locked. It does not result in a locked row on the account table but I think it should.

public static Account getLockedAccount(EntityManager em, String id, String type) {
        Query q = em.createNativeQuery("select A.* from account A, account_mapping M where M.identifier=? and M.identifier_type=? and M.account_id=A.account_id", Account.class);
        q.setParameter(1, id);
        q.setParameter(2, type);
        q.setLockMode(LockModeType.PESSIMISTIC_READ);
        Account acc = (Account) q.getSingleResult();
        return acc;
    }

Reproducible: Always

Steps to Reproduce:
1. Run similar code as provided
2.
3.
Comment 1 Tom Ware CLA 2011-04-06 09:24:36 EDT
It is a good idea to go through one of the various support mechanisms before filing a bug.  (users mailing list or the newsgroup)  The audience is fairly wide and the chance of you getting feedback about what is going wrong, whether it is a bug and a workaround is very good.  The feedback for items entered in the bug database will be slower.
Comment 2 Missing name Mising name CLA 2011-04-06 09:55:02 EDT
Thanks, I found a workaround by not doing a join and its fine. I logged the bug merely as a means for future improvement of the stack.
Comment 3 Tom Ware CLA 2011-04-28 10:00:58 EDT
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:21:22 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink