加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql – JPQL构造函数表达式,如何在’select new’中急切地获取主

发布时间:2020-12-12 07:28:16 所属栏目:MsSql教程 来源:网络整理
导读:我的原始查询有点复杂,但我要做的是获取实体AlertCondition以及一些其他字段. + " SELECT new org.rhq.core.domain.alert.composite.AlertConditionEventCategoryComposite " // + " ( " // + " ac," // + " res.id " // + " ) " // + " FROM AlertCondition
我的原始查询有点复杂,但我要做的是获取实体AlertCondition以及一些其他字段.
+ "  SELECT new org.rhq.core.domain.alert.composite.AlertConditionEventCategoryComposite " //
    + "       ( " //
    + "         ac," //
    + "         res.id " //
    + "       ) " //
    + "    FROM AlertCondition AS ac FETCH ALL PROPERTIES " //
    + "    JOIN ac.alertDefinition ad " //
    + "    JOIN ad.resource res " //
    + "   WHERE " + AlertCondition.RECOVERY_CONDITIONAL_EXPRESSION //
    + "     AND ( res.agent.id = :agentId OR :agentId IS NULL ) " //
    + "     AND ad.enabled = TRUE " //
    + "     AND ad.deleted = FALSE " //
    + "     AND ac.category = 'EVENT' " //
    + "ORDER BY ac.id"),//

问题是Hibernate只选择AlertCondition的ID,所以当访问这个对象时,这最终需要N 1选择,而我只想做1.

根据debug,select只获取ID列:

select alertcondi0_.ID as col_0_0_,alertdefin1_.ID as col_1_0_,resource2_.ID as col_2_0_

我想要回来的是* AlertCondition的所有领域.

我在Hibernate下找不到任何办法. JOIN FETCH在这里也没有真正起作用.

另一种方法是选择表格的每一列,我想避免.

解决方法

你可以通过以下方式告诉hibernate获取广告:
JOIN FETCH ac.alertDefinition ad

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读