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

Bug 330690

Summary: Incorrect SQL when enum used as query parameter that does not reference a mapping
Product: z_Archived Reporter: Ed Randall <ed.randall>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipselink.orm-inbox, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Project to demonstrate enum problem
none
Proposed fix none

Description Ed Randall CLA 2010-11-19 12:56:51 EST
Build Identifier: eclipselink-2.2.0.v20101117-r8503

2.2.0-M4 and M5 seem to have a problem binding enum value in a named query.

Using the query:
SELECT a FROM AnEntity a WHERE (a.anEnum = :anEnum AND NOT :anEnum IS NULL) OR (:anEnum IS NULL AND a.anEnum IS NULL)

the generated SQL is: 
SELECT PARENTCODE, ANENUM FROM ANENTITY WHERE (((ANENUM = VALUE1) AND NOT ((VALUE1 IS NULL))) OR ((VALUE1 IS NULL) AND (ANENUM IS NULL)))

This is our last blocker to EclipseLink migration, it works correctly using Toplink-Essentials 2.1.1-b31g where the generated SQL is:
SELECT PARENTCODE, ANENUM FROM ANENTITY WHERE (((ANENUM = ?) AND NOT ((? IS NULL))) OR ((? IS NULL) AND (ANENUM IS NULL)))



Reproducible: Always

Steps to Reproduce:
See attached project
Comment 1 Ed Randall CLA 2010-11-19 13:00:48 EST
Created attachment 183491 [details]
Project to demonstrate enum problem
Comment 2 Tom Ware CLA 2010-11-22 13:50:17 EST
I just ran using the latest 2.2.0 code.  I get the following:

SELECT PARENTCODE, ANENUM FROM ANENTITY WHERE (((ANENUM = ?) AND NOT ((? IS NULL))) OR ((? IS NULL) AND (ANENUM IS NULL)))
	bind => [VALUE1, VALUE1, VALUE1]

Is that what you are expecting?

(my test is was on MySQL)
Comment 3 Ed Randall CLA 2010-11-29 05:58:06 EST
That looks good, we will confirm when 2.2.0-M6 comes out.
Out of interest, do bug test cases we submit here get routinely converted in to official test cases, or do we need to be continuously vigilant?!
Thanks
Ed
Comment 4 Tom Ware CLA 2010-12-03 08:39:28 EST
Closing based on comments above.  Please reopen with more details if you still see the issue.

When we fix a bug, we add regression test cases for the bug we fix.  We do not typically add test cases for bugs we close as WORKSFORME.
Comment 5 Ed Randall CLA 2010-12-03 10:32:08 EST
I'm afraid it still fails using the latest 2.2.0-SNAPSHOT #130 2.2.0.v20101202-r8598, we are using HSQLDB as an in-memory test database and Oracle 10.2.0.5 for the final product.

[EL Config]: 2010-12-03 15:25:45.979--ServerSession(18248114)--Thread(Thread[main,5,main])--The access type for the persistent class [class scratch.eclipselink.enumargumentnullcheck.AnEntity] is set to [FIELD].
[EL Config]: 2010-12-03 15:25:45.996--ServerSession(18248114)--Thread(Thread[main,5,main])--The access type for the persistent class [class scratch.eclipselink.bidirectional.BiDirectionalParent] is set to [FIELD].
[EL Config]: 2010-12-03 15:25:46.004--ServerSession(18248114)--Thread(Thread[main,5,main])--The target entity (reference) class for the one to many mapping element [field children] is being defaulted to: class scratch.eclipselink.bidirectional.OneToManyChild.
[EL Config]: 2010-12-03 15:25:46.005--ServerSession(18248114)--Thread(Thread[main,5,main])--The access type for the persistent class [class scratch.eclipselink.constraint.OptionalOneToOneChild] is set to [FIELD].
[EL Config]: 2010-12-03 15:25:46.02--ServerSession(18248114)--Thread(Thread[main,5,main])--The target entity (reference) class for the one to one mapping element [field parent] is being defaulted to: class scratch.eclipselink.constraint.Parent.
[EL Config]: 2010-12-03 15:25:46.021--ServerSession(18248114)--Thread(Thread[main,5,main])--The access type for the persistent class [class scratch.eclipselink.mappedsuperclass.TestBase] is set to [FIELD].
[EL Config]: 2010-12-03 15:25:46.021--ServerSession(18248114)--Thread(Thread[main,5,main])--The access type for the persistent class [class scratch.eclipselink.mappedsuperclass.TestConcrete] is set to [FIELD].
[EL Config]: 2010-12-03 15:25:46.022--ServerSession(18248114)--Thread(Thread[main,5,main])--The access type for the persistent class [class scratch.eclipselink.embedded.Test2Base] is set to [FIELD].
[EL Config]: 2010-12-03 15:25:46.022--ServerSession(18248114)--Thread(Thread[main,5,main])--The access type for the persistent class [class scratch.eclipselink.embedded.Test2Concrete] is set to [FIELD].
[EL Config]: 2010-12-03 15:25:46.022--ServerSession(18248114)--Thread(Thread[main,5,main])--The access type for the persistent class [class scratch.eclipselink.bidirectional.OneToManyChild] is set to [FIELD].
[EL Config]: 2010-12-03 15:25:46.022--ServerSession(18248114)--Thread(Thread[main,5,main])--The target entity (reference) class for the many to one mapping element [field parent] is being defaulted to: class scratch.eclipselink.bidirectional.BiDirectionalParent.
[EL Config]: 2010-12-03 15:25:46.023--ServerSession(18248114)--Thread(Thread[main,5,main])--The access type for the persistent class [class scratch.eclipselink.constraint.Parent] is set to [FIELD].
[EL Config]: 2010-12-03 15:25:46.023--ServerSession(18248114)--Thread(Thread[main,5,main])--The target entity (reference) class for the one to one mapping element [field child] is being defaulted to: class scratch.eclipselink.constraint.OptionalOneToOneChild.
[EL Config]: 2010-12-03 15:25:46.023--ServerSession(18248114)--Thread(Thread[main,5,main])--The access type for the persistent class [class scratch.eclipselink.mappedsuperclass.TestId] is set to [FIELD].
[EL Config]: 2010-12-03 15:25:46.024--ServerSession(18248114)--Thread(Thread[main,5,main])--The access type for the persistent class [class scratch.eclipselink.embedded.Test2Embedded] is set to [FIELD].
[EL Config]: 2010-12-03 15:25:46.026--ServerSession(18248114)--Thread(Thread[main,5,main])--The column name for element [field name] is being defaulted to: NAME.
[EL Config]: 2010-12-03 15:25:46.031--ServerSession(18248114)--Thread(Thread[main,5,main])--The column name for element [field id] is being defaulted to: ID.
[EL Config]: 2010-12-03 15:25:46.031--ServerSession(18248114)--Thread(Thread[main,5,main])--The column name for element [field dateTime] is being defaulted to: DATETIME.
[EL Config]: 2010-12-03 15:25:46.038--ServerSession(18248114)--Thread(Thread[main,5,main])--The column name for element [field name] is being defaulted to: NAME.
[EL Config]: 2010-12-03 15:25:46.038--ServerSession(18248114)--Thread(Thread[main,5,main])--The alias name for the entity class [class scratch.eclipselink.enumargumentnullcheck.AnEntity] is being defaulted to: AnEntity.
[EL Config]: 2010-12-03 15:25:46.047--ServerSession(18248114)--Thread(Thread[main,5,main])--The column name for element [field parentCode] is being defaulted to: PARENTCODE.
[EL Config]: 2010-12-03 15:25:46.048--ServerSession(18248114)--Thread(Thread[main,5,main])--The alias name for the entity class [class scratch.eclipselink.bidirectional.BiDirectionalParent] is being defaulted to: BiDirectionalParent.
[EL Config]: 2010-12-03 15:25:46.049--ServerSession(18248114)--Thread(Thread[main,5,main])--The column name for element [field id] is being defaulted to: ID.
[EL Config]: 2010-12-03 15:25:46.049--ServerSession(18248114)--Thread(Thread[main,5,main])--The alias name for the entity class [class scratch.eclipselink.constraint.OptionalOneToOneChild] is being defaulted to: OptionalOneToOneChild.
[EL Config]: 2010-12-03 15:25:46.049--ServerSession(18248114)--Thread(Thread[main,5,main])--The column name for element [field parentId] is being defaulted to: PARENTID.
[EL Config]: 2010-12-03 15:25:46.049--ServerSession(18248114)--Thread(Thread[main,5,main])--The column name for element [field childName] is being defaulted to: CHILDNAME.
[EL Config]: 2010-12-03 15:25:46.05--ServerSession(18248114)--Thread(Thread[main,5,main])--The alias name for the entity class [class scratch.eclipselink.mappedsuperclass.TestConcrete] is being defaulted to: TestConcrete.
[EL Config]: 2010-12-03 15:25:46.05--ServerSession(18248114)--Thread(Thread[main,5,main])--The table name for entity [class scratch.eclipselink.mappedsuperclass.TestConcrete] is being defaulted to: TESTCONCRETE.
[EL Config]: 2010-12-03 15:25:46.05--ServerSession(18248114)--Thread(Thread[main,5,main])--The column name for element [field c] is being defaulted to: C.
[EL Config]: 2010-12-03 15:25:46.05--ServerSession(18248114)--Thread(Thread[main,5,main])--The column name for element [field name] is being defaulted to: NAME.
[EL Config]: 2010-12-03 15:25:46.05--ServerSession(18248114)--Thread(Thread[main,5,main])--The alias name for the entity class [class scratch.eclipselink.embedded.Test2Concrete] is being defaulted to: Test2Concrete.
[EL Config]: 2010-12-03 15:25:46.051--ServerSession(18248114)--Thread(Thread[main,5,main])--The table name for entity [class scratch.eclipselink.embedded.Test2Concrete] is being defaulted to: TEST2CONCRETE.
[EL Config]: 2010-12-03 15:25:46.051--ServerSession(18248114)--Thread(Thread[main,5,main])--The column name for element [field id] is being defaulted to: ID.
[EL Config]: 2010-12-03 15:25:46.051--ServerSession(18248114)--Thread(Thread[main,5,main])--The column name for element [field c1] is being defaulted to: C1.
[EL Config]: 2010-12-03 15:25:46.051--ServerSession(18248114)--Thread(Thread[main,5,main])--The column name for element [field effectiveTime] is being defaulted to: EFFECTIVETIME.
[EL Config]: 2010-12-03 15:25:46.051--ServerSession(18248114)--Thread(Thread[main,5,main])--The column name for element [field name] is being defaulted to: NAME.
[EL Config]: 2010-12-03 15:25:46.052--ServerSession(18248114)--Thread(Thread[main,5,main])--The alias name for the entity class [class scratch.eclipselink.bidirectional.OneToManyChild] is being defaulted to: OneToManyChild.
[EL Config]: 2010-12-03 15:25:46.052--ServerSession(18248114)--Thread(Thread[main,5,main])--The column name for element [field id] is being defaulted to: ID.
[EL Config]: 2010-12-03 15:25:46.052--ServerSession(18248114)--Thread(Thread[main,5,main])--The column name for element [field parentId] is being defaulted to: PARENTID.
[EL Config]: 2010-12-03 15:25:46.052--ServerSession(18248114)--Thread(Thread[main,5,main])--The column name for element [field childName] is being defaulted to: CHILDNAME.
[EL Config]: 2010-12-03 15:25:46.052--ServerSession(18248114)--Thread(Thread[main,5,main])--The alias name for the entity class [class scratch.eclipselink.constraint.Parent] is being defaulted to: Parent.
[EL Config]: 2010-12-03 15:25:46.052--ServerSession(18248114)--Thread(Thread[main,5,main])--The column name for element [field parentCode] is being defaulted to: PARENTCODE.
[EL Config]: 2010-12-03 15:25:46.07--ServerSession(18248114)--Thread(Thread[main,5,main])--The primary key column name for the mapping element [field parent] is being defaulted to: PARENTCODE.
[EL Config]: 2010-12-03 15:25:46.07--ServerSession(18248114)--Thread(Thread[main,5,main])--The foreign key column name for the mapping element [field parent] is being defaulted to: PARENTID.
[EL Info]: 2010-12-03 15:25:46.734--ServerSession(18248114)--Thread(Thread[main,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.2.0.v20101202-r8598
[EL Fine]: 2010-12-03 15:25:46.867--Thread(Thread[main,5,main])--Detected Vendor platform: org.eclipse.persistence.platform.database.HSQLPlatform
[EL Config]: 2010-12-03 15:25:46.88--ServerSession(18248114)--Connection(26474210)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
	platform=>HSQLPlatform
	user name=> "sa"
	datasource URL=> "jdbc:hsqldb:mem:testdb"
))
[EL Config]: 2010-12-03 15:25:46.881--ServerSession(18248114)--Connection(20287235)--Thread(Thread[main,5,main])--Connected: jdbc:hsqldb:mem:testdb
	User: SA
	Database: HSQL Database Engine  Version: 1.8.1
	Driver: HSQL Database Engine Driver  Version: 1.8.1
[EL Info]: 2010-12-03 15:25:47.189--ServerSession(18248114)--Thread(Thread[main,5,main])--file:/E:/wss/DEV/Bedrock/scratch/Scratch.bugs.jpa/target/classes/_TESTPU_url=jdbc:hsqldb:mem:testdb_user=sa login successful
[EL Fine]: 2010-12-03 15:25:47.216--ServerSession(18248114)--Connection(20287235)--Thread(Thread[main,5,main])--CREATE TABLE TESTCONCRETE (C VARCHAR(255), NAME VARCHAR(255), COL3 TIMESTAMP NOT NULL, COL2 VARCHAR(255) NOT NULL, PRIMARY KEY (COL3, COL2))
[EL Fine]: 2010-12-03 15:25:47.222--ServerSession(18248114)--Connection(20287235)--Thread(Thread[main,5,main])--CREATE TABLE TEST2CONCRETE (ID VARCHAR(255) NOT NULL, C1 VARCHAR(255), NAME VARCHAR(255), EFFECTIVETIME TIMESTAMP, CURRENTSTATE VARCHAR(255), PRIMARY KEY (ID))
[EL Fine]: 2010-12-03 15:25:47.222--ServerSession(18248114)--Connection(20287235)--Thread(Thread[main,5,main])--CREATE TABLE PARENT (PARENTCODE VARCHAR(255) NOT NULL, PRIMARY KEY (PARENTCODE))
[EL Fine]: 2010-12-03 15:25:47.223--ServerSession(18248114)--Connection(20287235)--Thread(Thread[main,5,main])--CREATE TABLE OPTIONAL_ONE_TO_ONE_CHILD (PARENTID VARCHAR(255) NOT NULL, CHILDNAME VARCHAR(255), PRIMARY KEY (PARENTID))
[EL Fine]: 2010-12-03 15:25:47.224--ServerSession(18248114)--Connection(20287235)--Thread(Thread[main,5,main])--CREATE TABLE BIDIRECTIONALPARENT (ID INTEGER NOT NULL, PARENTCODE VARCHAR(255), PRIMARY KEY (ID))
[EL Fine]: 2010-12-03 15:25:47.224--ServerSession(18248114)--Connection(20287235)--Thread(Thread[main,5,main])--CREATE TABLE ONE_TO_MANY_CHILD (ID INTEGER NOT NULL, CHILDNAME VARCHAR(255), PARENTID VARCHAR(255) NOT NULL, PRIMARY KEY (ID))
[EL Fine]: 2010-12-03 15:25:47.225--ServerSession(18248114)--Connection(20287235)--Thread(Thread[main,5,main])--CREATE TABLE ANENTITY (PARENTCODE BIGINT NOT NULL, ANENUM VARCHAR(255), PRIMARY KEY (PARENTCODE))
[EL Fine]: 2010-12-03 15:25:47.225--ServerSession(18248114)--Connection(20287235)--Thread(Thread[main,5,main])--ALTER TABLE BIDIRECTIONALPARENT ADD CONSTRAINT UNQ_BIDIRECTIONALPARENT_1 UNIQUE (PARENTCODE)
[EL Fine]: 2010-12-03 15:25:47.229--ServerSession(18248114)--Connection(20287235)--Thread(Thread[main,5,main])--ALTER TABLE OPTIONAL_ONE_TO_ONE_CHILD ADD CONSTRAINT FK_OPTIONAL_ONE_TO_ONE_CHILD_PARENTID FOREIGN KEY (PARENTID) REFERENCES PARENT (PARENTCODE)
[EL Fine]: 2010-12-03 15:25:47.229--ServerSession(18248114)--Connection(20287235)--Thread(Thread[main,5,main])--ALTER TABLE ONE_TO_MANY_CHILD ADD CONSTRAINT FK_ONE_TO_MANY_CHILD_PARENTID FOREIGN KEY (PARENTID) REFERENCES BIDIRECTIONALPARENT (PARENTCODE)
[EL Fine]: 2010-12-03 15:25:47.277--ServerSession(18248114)--Connection(20287235)--Thread(Thread[main,5,main])--SELECT PARENTCODE, ANENUM FROM ANENTITY WHERE (((ANENUM = VALUE1) AND NOT ((VALUE1 IS NULL))) OR ((VALUE1 IS NULL) AND (ANENUM IS NULL)))
[EL Fine]: 2010-12-03 15:25:47.283--ServerSession(18248114)--Thread(Thread[main,5,main])--CALL 1
[EL Warning]: 2010-12-03 15:25:47.284--UnitOfWork(15605470)--Thread(Thread[main,5,main])--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.0.v20101202-r8598): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Column not found: VALUE1 in statement [SELECT PARENTCODE, ANENUM FROM ANENTITY WHERE (((ANENUM = 'VALUE1') AND NOT ((VALUE1 IS NULL))) OR ((VALUE1 IS NULL) AND (ANENUM IS NULL)))]
Error Code: -28
Call: SELECT PARENTCODE, ANENUM FROM ANENTITY WHERE (((ANENUM = 'VALUE1') AND NOT ((VALUE1 IS NULL))) OR ((VALUE1 IS NULL) AND (ANENUM IS NULL)))
Query: ReadAllQuery(name="getItemWithOptionalEnumArgument" referenceClass=AnEntity sql="SELECT PARENTCODE, ANENUM FROM ANENTITY WHERE (((ANENUM = ?) AND NOT ((? IS NULL))) OR ((? IS NULL) AND (ANENUM IS NULL)))")
testGetItemWithOptionalEnumArgumentQuery failed : 
Internal Exception: java.sql.SQLException: Column not found: VALUE1 in statement [SELECT PARENTCODE, ANENUM FROM ANENTITY WHERE (((ANENUM = 'VALUE1') AND NOT ((VALUE1 IS NULL))) OR ((VALUE1 IS NULL) AND (ANENUM IS NULL)))]
Error Code: -28
Call: SELECT PARENTCODE, ANENUM FROM ANENTITY WHERE (((ANENUM = 'VALUE1') AND NOT ((VALUE1 IS NULL))) OR ((VALUE1 IS NULL) AND (ANENUM IS NULL)))
Query: ReadAllQuery(name="getItemWithOptionalEnumArgument" referenceClass=AnEntity sql="SELECT PARENTCODE, ANENUM FROM ANENTITY WHERE (((ANENUM = ?) AND NOT ((? IS NULL))) OR ((? IS NULL) AND (ANENUM IS NULL)))")
Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.0.v20101202-r8598): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Column not found: VALUE1 in statement [SELECT PARENTCODE, ANENUM FROM ANENTITY WHERE (((ANENUM = 'VALUE1') AND NOT ((VALUE1 IS NULL))) OR ((VALUE1 IS NULL) AND (ANENUM IS NULL)))]
Error Code: -28
Call: SELECT PARENTCODE, ANENUM FROM ANENTITY WHERE (((ANENUM = 'VALUE1') AND NOT ((VALUE1 IS NULL))) OR ((VALUE1 IS NULL) AND (ANENUM IS NULL)))
Query: ReadAllQuery(name="getItemWithOptionalEnumArgument" referenceClass=AnEntity sql="SELECT PARENTCODE, ANENUM FROM ANENTITY WHERE (((ANENUM = ?) AND NOT ((? IS NULL))) OR ((? IS NULL) AND (ANENUM IS NULL)))")
	at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:684)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:526)
	at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1716)
	at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:585)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:207)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:193)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:264)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:647)
	at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2558)
	at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2517)
	at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:411)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1080)
	at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:808)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1040)
	at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:384)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1126)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2904)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1508)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1490)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1464)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:484)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getResultList(EJBQueryImpl.java:741)
	at scratch.eclipselink.enumargumentnullcheck.Main.testGetItemWithOptionalEnumArgumentQuery(Main.java:33)
	at scratch.eclipselink.enumargumentnullcheck.Main.main(Main.java:53)
Caused by: java.sql.SQLException: Column not found: VALUE1 in statement [SELECT PARENTCODE, ANENUM FROM ANENTITY WHERE (((ANENUM = 'VALUE1') AND NOT ((VALUE1 IS NULL))) OR ((VALUE1 IS NULL) AND (ANENUM IS NULL)))]
	at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
	at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
	at org.hsqldb.jdbc.jdbcStatement.executeQuery(Unknown Source)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:887)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:598)
	... 23 more
Comment 6 Ed Randall CLA 2010-12-03 12:25:56 EST
A similar failure also occurs using an Apache Derby database in embedded mode.
Comment 7 Tom Ware CLA 2010-12-23 14:51:47 EST
The issue appears to be with the two (:anEnum IS NULL) parts of this query.  Workaround is two use two queries. and run them depening on the value of anEnum:

SELECT a FROM AnEntity a WHERE a.anEnum = :anEnum;
SELECT a FROM AnEntity a WHERE a.anEnum IS NULL

The code that converts parameters makes use of the converter that @Enumerated puts on the mapping, when the JPQL refers to a mapped attribute. (for instance: in (a.anEnum = :anEnum), a.anEnum is mapped to and uses the converter) That is why a.anEnum = :anEnum will work.

We will have to determine a way to convert the Enum when it is not directly related to a mapped field in the JPQL.

Because of these issues, for expressions like: (:anEnum IS NULL) whether the SQL works or not will depend on the JDBC driver's ability to convert Enums internally.
Comment 8 Tom Ware CLA 2011-01-11 14:40:37 EST
Created attachment 186552 [details]
Proposed fix

The attached fix defaults our behavior to use the ordinal number for an enumeration in the case where the segment of JPQL including the enum does not include a mapping.

e.g. a.anEnum = :param will use the EnumType from a.anEnum for the parameter, but :param IN NULL will default to use Ordinal.
Comment 9 Tom Ware CLA 2011-01-11 14:58:05 EST
Checked into trunk stream.  Fix is described above.

Reviewed by Chris Delahunt

Added test to JUnitJPQLTestSuite and tested with JPA and Core LRG
Comment 10 Ed Randall CLA 2011-01-14 04:33:46 EST
(In reply to comment #9)

Will that mean the fix will make it in to 2.2.0-RC2 ?
Comment 11 Ed Randall CLA 2011-01-14 05:27:51 EST
Confirmed fixed in eclipselink-2.3.0.v20110114-r8830

Still broken in eclipselink-2.2.0.v20110114-r8831

We'd really appreciate it if this could be available in the upcoming 2.2.0 release.
Comment 12 Tom Ware CLA 2011-01-14 08:12:39 EST
2.2 is in "showstopper mode" and this fix does not qualify.

Currently this is fixed in our trunk-stream and will appear in our 2.3 release that will be released this summer as part of the Eclipse simultaneous release.
Comment 13 Eclipse Webmaster CLA 2022-06-09 10:21:41 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink