Vlad Mihalcea (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZTQ0NDkwMmM2...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-15766?atlOrigin=eyJpIjoiZTQ0ND...
) HHH-15766 (
https://hibernate.atlassian.net/browse/HHH-15766?atlOrigin=eyJpIjoiZTQ0ND...
) UNION query doesn't preserve the original semicolons, and so it fails on PostgreSQL
(
https://hibernate.atlassian.net/browse/HHH-15766?atlOrigin=eyJpIjoiZTQ0ND...
)
Issue Type: Bug Assignee: Unassigned Components: hibernate-core Created: 26/Nov/2022 06:56
AM Priority: Major Reporter: Vlad Mihalcea (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
If we execute a query like this one on PostgreSQL:
List<String> topics = entityManager.createQuery("""
(
select c.name as name
from Category c
order by c.id
)
union
(
select t.name as name
from Tag t
order by t.id
)
""", String.class)
.getResultList();
The following exception is thrown:
n.t.d.l.l.SLF4JQueryLoggingListener - Name:DATA_SOURCE_PROXY, Connection:6, Time:20,
Success:False, Type:Prepared, Batch:False, QuerySize:1, BatchSize:0, Query:["select
c1_0.name from category c1_0 order by c1_0.id union select t1_0.name from tag t1_0 order
by t1_0.id"], Params:[()]
o.h.e.j.s.SqlExceptionHelper - SQL Error: 0, SQLState: 42601
o.h.e.j.s.SqlExceptionHelper - ERROR: syntax error at or near "union"
That’s because the generated SQL query does not preserve the semicolons:
select c1_0.name from category c1_0 order by c1_0.id
union
select t1_0.name from tag t1_0 order by t1_0.id
and this one fails in PostgreSQL.
If the semicolons were preserved, then this SQL query would have worked just fine:
(select c1_0.name from category c1_0 order by c1_0.id)
union
(select t1_0.name from tag t1_0 order by t1_0.id)
(
https://hibernate.atlassian.net/browse/HHH-15766#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15766#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100210- sha1:eab5823 )