I was trying to fire hql for some reporting purpose in my JPA based application.
The following query that I tried kept conking out on startup (Since I had given it as a NamedQuery, it was checked for syntax at startup).
Incorrect Query:
SELECT t FROM Table_1 tb1
INNER JOIN
Table_2 tb2
where tb1.name = 'someName';
After lot of permutations and combinations (and digging through the other parts of the query, which I suspected earlier), I realized the problem lied in the “t“. Instead of the query above, the correct query should have been…
SELECT tb1 FROM Table_1 tb1
INNER JOIN
Table_2 tb2
where tb1.name = 'someName';
Notice that HQL expects the tb1 to be same as the Table shortname “tb1“
The tableName shortform and the select mismatch only resulted in the issue that I was facing. Surprisingly, hibernate/JPA does not give an error in the stack, but the deployment keeps on running through and I need to ultimately kill the java process to get out of it.
Hope this helps someone.
It would great, if somebody could also reason this behaviour.
Thanks!!
The best way to deal with such statements it make it a PRACTICE to put the “Variable” in the SELECT clause same as the table Alias.
That is instead of
make a statment like
Hope that helps someone in the future.