• <bdo id='EYGSk'></bdo><ul id='EYGSk'></ul>
    <legend id='EYGSk'><style id='EYGSk'><dir id='EYGSk'><q id='EYGSk'></q></dir></style></legend>
    <i id='EYGSk'><tr id='EYGSk'><dt id='EYGSk'><q id='EYGSk'><span id='EYGSk'><b id='EYGSk'><form id='EYGSk'><ins id='EYGSk'></ins><ul id='EYGSk'></ul><sub id='EYGSk'></sub></form><legend id='EYGSk'></legend><bdo id='EYGSk'><pre id='EYGSk'><center id='EYGSk'></center></pre></bdo></b><th id='EYGSk'></th></span></q></dt></tr></i><div id='EYGSk'><tfoot id='EYGSk'></tfoot><dl id='EYGSk'><fieldset id='EYGSk'></fieldset></dl></div>

    <small id='EYGSk'></small><noframes id='EYGSk'>

  1. <tfoot id='EYGSk'></tfoot>

    1. 带有分页的 Spring-Data FETCH JOIN 不起作用

      Spring-Data FETCH JOIN with Paging is not working(带有分页的 Spring-Data FETCH JOIN 不起作用)
        <tbody id='5dEbU'></tbody>

      <small id='5dEbU'></small><noframes id='5dEbU'>

    2. <legend id='5dEbU'><style id='5dEbU'><dir id='5dEbU'><q id='5dEbU'></q></dir></style></legend>

    3. <tfoot id='5dEbU'></tfoot>

      1. <i id='5dEbU'><tr id='5dEbU'><dt id='5dEbU'><q id='5dEbU'><span id='5dEbU'><b id='5dEbU'><form id='5dEbU'><ins id='5dEbU'></ins><ul id='5dEbU'></ul><sub id='5dEbU'></sub></form><legend id='5dEbU'></legend><bdo id='5dEbU'><pre id='5dEbU'><center id='5dEbU'></center></pre></bdo></b><th id='5dEbU'></th></span></q></dt></tr></i><div id='5dEbU'><tfoot id='5dEbU'></tfoot><dl id='5dEbU'><fieldset id='5dEbU'></fieldset></dl></div>
                <bdo id='5dEbU'></bdo><ul id='5dEbU'></ul>
              • 本文介绍了带有分页的 Spring-Data FETCH JOIN 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试使用 HQL 来获取我的实体以及使用 JOIN FETCH 的子实体,如果我想要所有结果,这可以正常工作,但如果我想要页面则不是这样

                I am trying to use HQL fetching my entity along with sub-entities using JOIN FETCH, this is working fine if I want all the results but it is not the case if I want a Page

                我的实体是

                @Entity
                @Data
                public class VisitEntity {
                
                    @Id
                    @Audited
                    private long id;
                
                    .
                    .
                    .   
                
                    @OneToMany(cascade = CascadeType.ALL,)
                    private List<VisitCommentEntity> comments;
                }
                

                因为我有数百万次访问,所以我需要使用 Pageable,并且我想在单个数据库查询中获取评论,例如:

                and because I have millions of visits I need to use Pageable and I want to Fetch the comments in a single database query like :

                @Query("SELECT v FROM VisitEntity v LEFT JOIN FETCH v.comments WHERE v.venue.id = :venueId and ..." )
                public Page<VisitEntity> getVenueVisits(@Param("venueId") long venueId,...,
                        Pageable pageable);
                

                该 HQL 调用引发以下异常:

                That HQL call throws the following exception:

                Caused by: java.lang.IllegalArgumentException: 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=null,role=com.ro.lib.visit.entity.VisitEntity.comments,tableName=visitdb.visit_comment,tableAlias=comments1_,origin=visitdb.visit visitentit0_,columns={visitentit0_.visit_id ,className=com.ro.lib.visit.entity.VisitCommentEntity}}] [select count(v) FROM com.ro.lib.visit.entity.VisitEntity v LEFT JOIN FETCH v.comments WHERE v.venue.id = :venueId and (v.actualArrival > :date or v.arrival > :date)]
                at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1374)
                at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
                at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:309)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                

                一旦我删除分页,一切正常

                and once I remove the paging everything works fine

                @Query("SELECT v FROM VisitEntity v LEFT JOIN FETCH v.comments WHERE v.venue.id = :venueId and  ..." )
                public List<VisitEntity> getVenueVisits(@Param("venueId") long venueId,...);
                

                显然问题是来自 Spring-Data 的计数查询,但我们该如何解决呢?

                Obviously the problem is the count query from Spring-Data, but how can we fix it?

                推荐答案

                最简单的方法是使用 @Query 注解的 countQuery 属性提供自定义要使用的查询.

                The easiest way is to use the countQuery attribute of the the @Query annotation to provide a custom query to be used.

                @Query(value = "SELECT v FROM VisitEntity v LEFT JOIN FETCH v.comments …",
                       countQuery = "select count(v) from VisitEntity v where …")
                List<VisitEntity> getVenueVisits(@Param("venueId") long venueId, …);
                

                这篇关于带有分页的 Spring-Data FETCH JOIN 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                  <tfoot id='Wcant'></tfoot>
                    <legend id='Wcant'><style id='Wcant'><dir id='Wcant'><q id='Wcant'></q></dir></style></legend>
                      <bdo id='Wcant'></bdo><ul id='Wcant'></ul>
                      • <small id='Wcant'></small><noframes id='Wcant'>

                        <i id='Wcant'><tr id='Wcant'><dt id='Wcant'><q id='Wcant'><span id='Wcant'><b id='Wcant'><form id='Wcant'><ins id='Wcant'></ins><ul id='Wcant'></ul><sub id='Wcant'></sub></form><legend id='Wcant'></legend><bdo id='Wcant'><pre id='Wcant'><center id='Wcant'></center></pre></bdo></b><th id='Wcant'></th></span></q></dt></tr></i><div id='Wcant'><tfoot id='Wcant'></tfoot><dl id='Wcant'><fieldset id='Wcant'></fieldset></dl></div>

                          <tbody id='Wcant'></tbody>