Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 327411 - Generation of invalid SQL from JPQL: SELECT columns don't reference defined table aliases
Summary: Generation of invalid SQL from JPQL: SELECT columns don't reference defined t...
Status: CLOSED WORKSFORME
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-10 20:36 EDT by andis CLA
Modified: 2022-06-09 10:03 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description andis CLA 2010-10-10 20:36:30 EDT
Build Identifier: Eclipselink 1.1.3 installed by default under Eclipse for Java EE build 20090621-0832

Eclipselink 1.1.3 generates invalid SQL that doesn't use set table aliases.

Creating JPQL query:

select c from Client c, Order ord WHERE ord.client=c and c.id=400

Ends with invalid SQL :

SELECT clients.clt_id, clients.clt_name FROM orders t0, clients t1 
WHERE ((t0.ord_cli_id = t1.clt_id) AND (t0.ord_id = ?))

Using PostgreSQL 8.1 it generates following error:

Internal Exception: org.postgresql.util.PSQLException: ERROR: invalid reference to FROM-clause entry for table 

"clients"
  Wskazówka: Perhaps you meant to reference the table alias "t1".
  Pozycja: 8
Error Code: 0
Call: SELECT clients.clt_id, clients.clt_name FROM orders t0, clients t1 WHERE ((t0.ord_cli_id = t1.clt_id) AND 

(t0.ord_id = ?))
	bind => [400]


EclipseLink should use clients alias "t1" while referencing clients table, not "clients" table name. 



This is an invalid use of SQL. PostgreSQL 8.1 is serious and strict about this rule 

(http://www.network-theory.co.uk/docs/postgresql/vol1/TableandColumnAliases.html):

"The alias becomes the new name of the table reference for the current query--it is no longer possible to refer to the 

table by the original name."






Reproducible: Always

Steps to Reproduce:
Entities
Client (maps to table name: clients)
id (maps to column name: cli_id)
name (column name: cli_name)

Order (table name: orders)
id (column name: ord_id)
date (column name: ord_date)
client (join column: ord_cli_id, refColumnName: cli_id)

Execute following query:

select c from Client c, Order ord WHERE ord.client=c and c.id=400
Comment 1 Tom Ware CLA 2010-10-14 13:30:38 EDT
Does this problem still occur in EclipseLink 2.1.1?
Comment 2 andis CLA 2010-10-23 11:11:03 EDT
(In reply to comment #1)
> Does this problem still occur in EclipseLink 2.1.1?

I have just checked the issue.

The problem DOESN'T occur in EclipseLink 2.1.1, but it DOES occur also in 1.1.4.

Rgds
Comment 3 Tom Ware CLA 2010-10-25 07:47:23 EDT
Setting to WorksForMe.  This works on the latest patch release.
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:03:10 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink