JonH
JonH

Reputation: 501

Changing sql to hql with joins

What seems to be wrong with my hql query?

String queryString = "SELECT A.INITIAL, A.NUMBER, A.OWNR_SCAC , A.INITIAL||A.NUMBER AS CAR," + 
            "A.LESSEE_SCAC, A.TRUK_CNT, A.EQP_TYP_CD, A.AXL_CNT, B.STABILITY_DEV_EQP," +
            "A.C_CNT, A.G_WGT, B.TRUK_AXL_CNT, A.EIN FROM DS.E_UT AS A" +
            "LEFT JOIN DS.E_PRIMARY AS B" +
            "WHERE A.INITIAL||A.NUMBER IN (:carList) AND A.INITIAL IN {:initList) AND A.NUMBER IN (:numberList)" + 
            "AND B.TRUK_AXL_CNT > 0";

ERROR:

org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: A near line 1, column 263

I assume it is talking about the A after FROM DS.E_UT AS A

Upvotes: 0

Views: 1228

Answers (3)

John Kane
John Kane

Reputation: 4443

I am not entirely sure of your schema or if this is what you are looking for, but you could just map your joined tables together. This could make things a little easier and you wouldnt need to explicitly join in your query.

Here is a small example

A sample query from that example could look something like:

SELECT p 
    FROM Person 
WHERE p.name like :name 
AND p.address.street like :street

Upvotes: 1

Deruijter
Deruijter

Reputation: 2159

I think you should add some spaces on each new line.

"A.C_CNT, A.G_WGT, B.TRUK_AXL_CNT, A.EIN FROM DS.E_UT AS A" +
"LEFT JOIN DS.E_PRIMARY AS B"

Would become:

A.C_CNT, A.G_WGT, B.TRUK_AXL_CNT, A.EIN FROM DS.E_UT AS ALEFT JOIN DS.E_PRIMARY AS B

Note the 'ALEFT'

Upvotes: 1

Johanna
Johanna

Reputation: 5293

In HQL you do not give the table and column names. Instead you give the Java class names and member variable names (or getter/setter) names of the classes and member variables which you mapped to the tables and columns.

Upvotes: 2

Related Questions