tags:

views:

16

answers:

2

Hello, 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!!

A: 

I'm not sure to understand the question but if you think that Hibernate should be improved in the way it reported (or not) your syntactically incorrect NamedQuery at EntityManagerFactory creation time, you should create an issue. I don't think it will get a high priority though.

Pascal Thivent
First of all apologies to come back to this after long. The problem put straight is that "Select t from Table_1 t1" DOES NOT work (nor does it give a sensible error message).However, the workaround or the solution is to make the statement "select T1 From Table_1 T1".To summarize, the "variable" in the select clause should be same as the Table alias that we provide (T1 and T1 in this case).
PaiS
A: 

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

"SELECT t from Table_1 T1" 

make a statment like

"SELECT T1 from Table_1 T1"

Hope that helps someone in the future.

PaiS