Search code examples
javaoracle-databasejpaeclipselinknamed-query

Strange behaviour when executing query on Oracle with EclipseLink


I created a namedquery as follows:

SELECT o
FROM TableName1Entity o , TableName2Entity a
WHERE o.field1 = a.field4
AND a.field5 = :param1

That is converted to the following sql:

SELECT TABLE_NAME1.FIELD1, TABLE_NAME1.FIELD2, TABLE_NAME1.FIELD3
FROM TABLE_NAME2 t0, TABLE_NAME1 t1
WHERE ((t0.FIELD4 = t1.FIELD1)
AND (t0.FIELD5 = ?));

And it returns ORA-00904: "TABLE_NAME1"."FIELD3": invalid identifier

But it works when I manually modify as follows: (they all work as expected)

SELECT t1.FIELD1, t1.FIELD2, t1.FIELD3
FROM TABLE_NAME2 t0, TABLE_NAME1 t1
WHERE ((t0.FIELD4 = t1.FIELD1)
AND (t0.FIELD5 = ?));

SELECT TABLE_NAME1.FIELD1, TABLE_NAME1.FIELD2, TABLE_NAME1.FIELD3
FROM TABLE_NAME2 t0, TABLE_NAME1
WHERE ((t0.FIELD4 = TABLE_NAME1.FIELD1)
AND (t0.FIELD5 = ?));

SELECT FIELD1, FIELD2, FIELD3
FROM TABLE_NAME2 t0, TABLE_NAME1 t1
WHERE ((t0.FIELD4 = t1.FIELD1) AND (t0.FIELD5 = ?));

SELECT FIELD1, FIELD2, FIELD3
FROM TABLE_NAME2 t0, TABLE_NAME1
WHERE ((t0.FIELD4 = TABLE_NAME1.FIELD1)
AND (t0.FIELD5 = ?));

PS.: for security reasons, I cant give table or field names.

The thing is: when the table name is explicitly set along with a label to it, the query doesn't work.

Please, don't give alternative solutions by changing the named query because it should be fine as is and changing the named query is not an option. unless it really has an error.


Solution

  • Change the version of EclipseLink from 1.1.1 to 2.0.0