查询指定的联接抓取,但抓取的关联的所有者不在选择列表中 [英] query specified join fetching, but the owner of the fetched association was not present in the select list

查看:92
本文介绍了查询指定的联接抓取,但抓取的关联的所有者不在选择列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  org.hibernate.QueryException:**查询指定的连接但获取的关联的所有者不在选择列表中** 

[FromElement {显式,不是集合连接,访存连接,获取非惰性属性,classAlias = r,角色= null,tableName = REVISIONS,tableAlias = revision1_,origin = ENTITY_CHANGED_IN_REVISION entitychan0_,columns = {entitychan0_.REV_ID,className = ru.csbi.registry.domain.envers.Revision}}] [select ec.id as entityChangeId,r.id as ru.csbi.registry.domain.envers.EntityChange作为revisionId作为ec内部联接获取ec.revision作为r其中ec.groupEntityId =:groupEntityId和ec.groupName =:groupName和r.timestamp< :entityDateFrom和r.timestamp> :entityDateTo和(ec.revisionType in(0,5,1,4,2)and not(ec.otherGroupEntityModified = false and ec.thisGroupEntityModified = true and ec.rowDataModified = false and ec.collectionOfNotGroupEntityModified = false))group by ec .id,r.id具有计数(*)> :以r.id开始订单]

部分代码:

  String hql =select ec.id as entityChangeId,r.id as EntityChange的revisionId as ec+ 
inner join fetch ec.revision as r +
其中ec.groupEntityId =:groupEntityId+
和ec.groupName =:groupName+
和r.timestamp<:entityDateFrom+
和r.timestamp>:entityDateTo+
和(+
ec.revisionType in(+
RevisionType.ADD.getRepresentation()+,+
RevisionType.ONLY_DATA_PROPERTY_MOD.getRepresentation()+,+
RevisionType.BOTH_COLLECTION_AND_PROPERTY_MOD.getRepresentation()+,+
RevisionType.ONLY_COLLECTION_PROPERTY_MOD.getRepresentation()+,+
RevisionType .DEL.getRepresentation( )+
)+
而不是(+
ec.otherGroupEntityModified = false和+
ec.thisGroupEntityModified = true和+
ec.rowDataModified = false和+
ec.collectionOfNotGroupEntityModified = false+
)+
)+
group by ec.id,r。 id+
有count(*)> :开始+
by r.id desc;

如何解决错误和我做错了什么?

解决方案

改为使用常规连接 加入fetch (顺便说一下,默认情况下它是 inner ):

  String hql =select ec.id as entityChangeId,r.id as revisionId from EntityChange as ec+ 
ec.revision as r+。 ..

由于错误消息告诉您,加入获取在这里没有意义,因为这是一个强制加载收集的性能提示。


I'm selecting two id columns but get error specified:

org.hibernate.QueryException: **query specified join fetching, but the owner of the fetched association was not present in the select list** 

[FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=r,role=null,tableName=REVISIONS,tableAlias=revision1_,origin=ENTITY_CHANGED_IN_REVISION entitychan0_,columns={entitychan0_.REV_ID ,className=ru.csbi.registry.domain.envers.Revision}}] [ select ec.id as entityChangeId, r.id as revisionId from ru.csbi.registry.domain.envers.EntityChange as ec  inner join fetch ec.revision as r  where ec.groupEntityId = :groupEntityId and ec.groupName = :groupName  and r.timestamp < :entityDateFrom  and r.timestamp > :entityDateTo  and (        ec.revisionType in (0, 5, 1, 4, 2 )       and not ( ec.otherGroupEntityModified = false and ec.thisGroupEntityModified = true and ec.rowDataModified = false and ec.collectionOfNotGroupEntityModified = false   )      )  group by ec.id, r.id  having count(*) > :start order by r.id desc]

Some code:

String hql = " select ec.id as entityChangeId, r.id as revisionId from EntityChange as ec " +
            " inner join fetch ec.revision as r " +
            " where ec.groupEntityId = :groupEntityId" +
            " and ec.groupName = :groupName " +
            " and r.timestamp < :entityDateFrom " +
            " and r.timestamp > :entityDateTo " +
            " and ( " +
            "       ec.revisionType in (" + 
                        RevisionType.ADD.getRepresentation() + ", " + 
                        RevisionType.ONLY_DATA_PROPERTY_MOD.getRepresentation() + ", " +
                        RevisionType.BOTH_COLLECTION_AND_PROPERTY_MOD.getRepresentation() + ", " +
                        RevisionType.ONLY_COLLECTION_PROPERTY_MOD.getRepresentation() + ", " +
                        RevisionType.DEL.getRepresentation() +
                    " ) " +
            "     and not ( "+
                    "ec.otherGroupEntityModified = false and " +
                    "ec.thisGroupEntityModified = true and " +
                    "ec.rowDataModified = false and " +
                    "ec.collectionOfNotGroupEntityModified = false " +
                "  ) " +
            "     ) " +
            " group by ec.id, r.id " +
            " having count(*) > :start" +
            " order by r.id desc";

How to fix the error and what am I doing wrong?

解决方案

Use regular join instead of join fetch (by the way, it's inner by default):

String hql = " select ec.id as entityChangeId, r.id as revisionId from EntityChange as ec " + 
        " join ec.revision as r " + ...

As error message tells you, join fetch doesn't make sense here, because it's a performance hint that forces eager loading of collection.

这篇关于查询指定的联接抓取,但抓取的关联的所有者不在选择列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆