Error: Encountered a duplicated sql alias

2.1k Views Asked by At

I want to left join the table via createNativeQuery in Hibernate/JPA.

Hence I wrote this query:

final Query query = entityManager.createNativeQuery("Select * FROM program p LEFT JOIN tester vt on p.test_id = vt.test_id LEFT JOIN vendor bv on vt.vendor_id = bv.vendor_id
LEFT JOIN alpha_program bp on p.program_id = bp.program_id where vt.status IN ('BLOCKED') ORDER BY p.creation_date asc limit 30");

But When I try to execute this, I am getting the exception

Caused by: org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException: Encountered a duplicated sql alias [tester_id] during auto-discovery of a native-sql query

What i am missing here ? Can AnyOne help on this.

1

There are 1 best solutions below

0
Alien On

Looke like it is related to ambiguous columns in tables.

Select * is selecting all the columns of all the tables and one of the column name is same.

Just check if the columns are unique accross all the tables or select the columns with specific alias.