我创建了一个命名查询,如下所示:
SELECT o
FROM TableName1Entity o , TableName2Entity a
WHERE o.field1 = a.field4
AND a.field5 = :param1
即转换为以下 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 = ?));
它返回ORA-00904: "TABLE_NAME1"."FIELD3": invalid identifier
但是当我手动修改如下时它可以工作:(它们都按预期工作)
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.:出于安全原因,我不能给出表或字段名。
问题是:当表名与标签一起显式设置时,查询不起作用。
请不要通过更改命名查询来提供替代解决方案,因为它应该可以按原样进行,并且更改命名查询不是一种选择。除非它真的有错误。