使用连接将sql更改为hql

时间:2012-05-23 13:35:54

标签: sql hibernate hql

我的hql查询似乎有什么问题?

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:意外令牌:近线1,第263列

我认为它是在A

之后讨论FROM DS.E_UT AS A

3 个答案:

答案 0 :(得分:2)

在HQL中,您可以给出表名和列名。而是给出映射到表和列的类和成员变量的Java类名和成员变量名(或getter / setter)名称。

答案 1 :(得分:1)

我认为你应该在每一个新行上添加一些空格。

"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"

会变成:

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

请注意'ALEFT'

答案 2 :(得分:1)

我不完全确定您的架构或者这是您正在寻找的,但您可以将连接的表格映射到一起。这可以使事情变得更容易,您不需要明确地加入您的查询。

Here is a small example

该示例的示例查询可能类似于:

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