Chinaunix首页 | 论坛 | 博客
  • 博客访问: 596227
  • 博文数量: 765
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 5005
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-16 18:49
文章分类

全部博文(765)

文章存档

2011年(1)

2008年(764)

我的朋友

分类:

2008-10-16 18:55:57

   在使用Hibernate进行分页的过程中,如果你收到如下警告,那么这里就是一个潜在的性能问题点:

WARNING: firstResult/maxResults specified with collection fetch; applying in memory!

  出现这个警告的直接后果是:无论你想要看第几页的数据,从Hibernate打印出的SQL来看它总是查询了所有满足条件的结果。这是为什么呢?来看看这句警告所在的代码,它位于org.hibernate.hql.ast.QueryTranslatorImpl中,部分摘录如下:

view plaincopy to clipboardprint?
QueryNode query = ( QueryNode ) sqlAst;

boolean hasLimit = queryParameters.getRowSelection() != null && queryParameters.getRowSelection().definesLimits();

boolean needsDistincting = ( query.getSelectClause().isDistinct() || hasLimit ) && containsCollectionFetches();

QueryParameters queryParametersToUse;

if ( hasLimit && containsCollectionFetches() ) {

     log.warn( "firstResult/maxResults specified with collection fetch; applying in memory!" );

    RowSelection selection = new RowSelection();

    selection.setFetchSize( queryParameters.getRowSelection().getFetchSize() );

    selection.setTimeout( queryParameters.getRowSelection().getTimeout() );

    queryParametersToUse = queryParameters.createCopyUsing( selection );

}

else {

    queryParametersToUse = queryParameters;

}

[1]  

【责编:landy】

--------------------next---------------------

阅读(614) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~