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

Bug 312847

Summary: EclipseLink doesn't escape column names, when it's a mysql keyword
Product: z_Archived Reporter: G. Zsombor <zombi>
Component: EclipselinkAssignee: Project Inbox <eclipselink.orm-inbox>
Status: CLOSED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: be.ellenberger, edpeur, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description G. Zsombor CLA 2010-05-13 17:47:34 EDT
Build Identifier: 2.0.1

When an entity has a attribute 'key', EclipseLink can't load from MySQL, because it's fails to properly escape it, for example it generates the following query : 
SELECT VALUE, SITE, LANGUAGE, KEY FROM messages WHERE (((SITE = ?) AND (LANGUAGE = ?)) AND (KEY = ?))

However it should be something like this: 
SELECT VALUE, SITE, LANGUAGE, 'KEY' FROM messages WHERE (((SITE = ?) AND (LANGUAGE = ?)) AND ('KEY' = ?))




Reproducible: Always

Steps to Reproduce:
1. Create an entity with attribute named 'key'
2. Try to store/load/query from MySQL
3. 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 'KEY .....
Comment 1 Tom Ware CLA 2010-05-14 08:11:50 EDT
This is not a bug.  EclipseLink does not maintain a list of keywords for each platform.  You should escape this attribute yourself when you map it. (in the @Column definition or the xml)
Comment 2 Benjamin Ellenberger CLA 2016-07-27 02:34:24 EDT
As a preferred escaping method, use "\"KEY\"" in the @Column“s name if you wish to escape it. JPA 2.0 does provide support for using escaped names and this functionality is already present in EclipseLink 2.0 builds.
Comment 3 Missing name CLA 2019-06-04 15:08:50 EDT
Does that mean that I am supposed to escape every column name if I want my application to work with multiple databases?
I would prefer that EclipseLink maintained the list of reserved words for each database.
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:04:27 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:11:00 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink