Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 369893 - setLockMode with setMaxResults generates incorrect SQL on MySQL 5.5.8
Summary: setLockMode with setMaxResults generates incorrect SQL on MySQL 5.5.8
Status: RESOLVED DUPLICATE of bug 380101
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P2 minor with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-27 00:16 EST by Willie Loyd Tandingan CLA
Modified: 2022-06-09 10:31 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Willie Loyd Tandingan CLA 2012-01-27 00:16:49 EST
Build Identifier: 2.3.0.v20110604-r9504

The following code throws a MySQLSyntaxErrorException on query.getResultList():

Query query = em.createQuery("SELECT p FROM WorkUnit p WHERE p.worker IS NULL");
query.setLockMode(LockModeType.PESSIMISTIC_FORCE_INCREMENT);
query.setMaxResults(workUnitsToGive);
List<WorkUnit> workUnits = query.getResultList();


Exception thrown:

Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0, 2' at line 1
Error Code: 1064
Call: SELECT ID AS a1, DATA AS a2, RESULT AS a3, VERSION AS a4, PROJECT_ID AS a5, WORKER_ID AS a6 FROM WORKUNIT WHERE (WORKER_ID IS NULL) FOR UPDATE LIMIT ?, ?
	bind => [2 parameters bound]


I believe that LIMIT ?, ? should come before FOR UPDATE.

Reproducible: Always
Comment 1 Tom Ware CLA 2012-02-17 10:45:16 EST
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 2 Martin CLA 2014-02-20 03:35:27 EST
Confirming the bug in 2.6.0.v20140121-d4012b7

Tried also with query.setHint(QueryHints.PESSIMISTIC_LOCK, PessimisticLock.LockNoWait); but got the same invalid SQL.

Instead "... FOR UPDATE LIMIT ?, ?" should be "... LIMIT ?, ? FOR UPDATE".
Comment 3 Lukas Jungmann CLA 2014-04-30 17:40:37 EDT
looks like a dup of issue #380101 to which I've just attached a patch
Comment 4 Tomas Kraus CLA 2014-05-05 09:45:09 EDT
Duplicate of Bug# 380101

*** This bug has been marked as a duplicate of bug 380101 ***
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:31:44 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink