【问题标题】:HQL Projection creates an issueHQL 投影产生问题
【发布时间】:2012-07-22 16:06:30
【问题描述】:

我在查询中添加了一个投影,它创建了一个类似...的查询

link

select
    this_.TEMPLATE_ID as y0_,
    this_.TEMPLATE_NAME as y1_,
    this_.CREATE_DATE as y2_,
    this_.UPDATE_DATE as y3_,
    this_.STATUS_CODE as y4_,
    this_.USER_ID as y5_,
    this_.UPDATED_BY as y6_,
    this_.CATEGORY_ID as y7_,
    this_.PRACTICE_ID as y8_ 
from
    templates this_ 
inner join
    user user1_ 
        on this_.USER_ID=user1_.USER_ID 
inner join
    template_categories category2_ 
        on this_.CATEGORY_ID=category2_.CATEGORY_ID 
where
    y4_=? 
    and y8_=? 
    and y5_ in (
        ?, ?
    ) 
order by
    y1_ asc limit ?

现在问题就像.. Unknown column 'y4_' in 'where clause' 和 y8_ 的相同错误,y5_ 表示所有关闭它给出错误的地方。

我将其修改为 Query like ...

select
    this_.TEMPLATE_ID as y0_,
    this_.TEMPLATE_NAME as y1_,
    this_.CREATE_DATE as y2_,
    this_.UPDATE_DATE as y3_,
    this_.STATUS_CODE as y4_,
    this_.USER_ID as y5_,
    this_.UPDATED_BY as y6_,
    this_.CATEGORY_ID as y7_,
    this_.PRACTICE_ID as y8_ 
from
    templates this_ 
inner join
    user user1_ 
        on this_.USER_ID=user1_.USER_ID 
inner join
    template_categories category2_ 
        on this_.CATEGORY_ID=category2_.CATEGORY_ID 
where
    this_.STATUS_CODE=1
    and this_.PRACTICE_ID=1 
    and this_.USER_ID in (
        1, 2
    ) 
order by
    y1_ asc limit ?

它奏效了。但是不知道HQL怎么修改?

【问题讨论】:

标签: java mysql hibernate hql


【解决方案1】:

我只是使用了 this.fieldName 并解决了问题。 看帖子

Hibernate Query By Example and Projections

【讨论】:

    猜你喜欢
    • 2023-04-11
    • 2014-08-20
    • 2017-07-30
    • 2017-08-25
    • 1970-01-01
    • 2017-06-21
    • 2014-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多