We're updating the issue view to help you get more done. 

HQLParser generates erroneous MySQL query for join table.

Description

Two tables (ledger and person) in a MySQL database (scc-data) in a one-to-many relationship are linked by a join table (trx_person). The Java Ledger class contains a Person that optionally represents the individual associated with a given transaction, and the Person class contains a collection of transactions in which the individual has participated. The join table links the two by their primary keys, denominated trx_ID and person_ID.

Retrieving all ledger entries using HQL produces an error in the generated SQL query:

INFO: Query String: FROM Ledger t

2017-Oct-20 12:26:50 PM [http-nio-8080-exec-1] DEBUG org.hibernate.SQL -
/*
FROM
Ledger t */ select
ledger0_.id as id1_0_,
ledger0_.balance as balance2_0_,
ledger0_.credit as credit3_0_,
ledger0_.date as date4_0_,
ledger0_.debit as debit5_0_,
ledger0_.remarks as remarks6_0_,
ledger0_.type as type7_0_,
ledger0_.version as version8_0_,
ledger0_.xref as xref9_0_,
ledger0_1_.person_ID as person_I1_4_
from
ledger ledger0_
left outer join
scc-data.trx_person ledger0_1_
on ledger0_.id=ledger0_1_.trx_ID

2017-Oct-20 12:26:50 PM [http-nio-8080-exec-1]
ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper -
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 '-data.trx_person ledger0_1_ on ledger0_.id=ledger0_1_.trx_ID' at line 1

Running the generated SQL query in MySQL Workbench produces the identical error.

The defect in the generated SQL is the lack of back ticks surrounding the Schema. After supplying them (`scc-data`.trx-person), the query executes perfectly.

Environment

Windows 10/MySQL InnoDB
hibernate-core version 5.2.11.Final
Eclipse IDE for Java EE Developers 4.7.1.20171009-0537

Status

Assignee

Unassigned

Reporter

Robert F. Peake

Worked in

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Community Help Wanted

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Affects versions

1.5

Priority

Minor