Ofir Prizat
Ofir Prizat

Reputation: 154

What's wrong with this HQL? Where is the missing comma?

I'm getting this hibernate exception:

 org.hibernate.QueryException: , expected in SELECT [select tc.id as
 id, tc.terminalServerPort.id as terminalServerPortId,
 tc.terminalServerPort.terminalServer.name as terminalServerName,
 tc.terminalServerPort.terminalServer.ipConfig.ipAddress as
 terminalServerIpAddress, tc.terminalServerPort.portNumber as
 terminalServerPort from
 com.windriver.dsm.labmanagement.data.TargetConsole tc where
 tc.target.id = :targetId order by id asc]

Any ideas? Thanks!

Upvotes: 4

Views: 683

Answers (3)

You need to configure your hibernate translator property for the sessionFactory which you are using.

hibernate.query.factory_class = org.hibernate.hql.ast.ASTQueryTranslatorFactory

Upvotes: 1

Ofir Prizat
Ofir Prizat

Reputation: 154

I found the solution.

Apparently the hibernate version which I'm using (hibernate 3) does not allow assigning aliases to associated entities. When I remove those aliases - the query works.

Here is the correct code:

select tc.id, tc.terminalServerPort.id, 
tc.terminalServerPort.terminalServer.name, 
tc.terminalServerPort.terminalServer.IPConfig.IPAddress, 
tc.terminalServerPort.portNumber 
from TargetConsole tc where tc.target.id = :targetId order by id asc

Thanks for the help guys!

Upvotes: 1

gprathour
gprathour

Reputation: 15333

Even when I narrow the HQL to the minimum I still get that exception - , expected in SELECT [select tc.id as id from com.windriver.dsm.labmanagement.data.TargetConsole as tc]

Shouldn't you write it this way?

[select tc.id as id from com.windriver.dsm.labmanagement.data.TargetConsole tc]

Why are you writing as when giving alias to table?

Upvotes: 1

Related Questions