[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-7175) Possible problem with org.hibernate.engine.query.HQLQueryPlan
Imrich Olha (JIRA)
noreply at atlassian.com
Fri Mar 16 04:37:49 EDT 2012
[ https://hibernate.onjira.com/browse/HHH-7175?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45984#comment-45984 ]
Imrich Olha commented on HHH-7175:
----------------------------------
My suggestion for correction (shown on my simplified example):
int includedCount = -1;
for ( int x = 0; x < size; x++ ) {
final Object result = tmp.get( x );
includedCount++;
if ( max >= 0 && includedCount {color:red}>={color} max ) { // break the outer loop !!! break translator_loop; }
{color:red}combinedResults.add( result );{color}
}
> Possible problem with org.hibernate.engine.query.HQLQueryPlan
> -------------------------------------------------------------
>
> Key: HHH-7175
> URL: https://hibernate.onjira.com/browse/HHH-7175
> Project: Hibernate ORM
> Issue Type: Bug
> Components: core
> Environment: hibernate-core-3.3.2.GA.jar, Oracle DB, Java(TM) SE Runtime Environment (build 1.6.0_31-b04)
> Reporter: Imrich Olha
> Priority: Minor
>
> I wrote a simple 'polymorphic' queryString for org.hibernate.Query based on interface implemented by three other classes.
> I set restriction on size (maxRows) too.
> But when I executed that query, I found that some records where missing in returned list.
> I debugged sources and found possible issue in org.hibernate.engine.query.HQLQueryPlan in method
> public List performList(QueryParameters queryParameters, SessionImplementor session) throws HibernateException { ... }
> specifically in branch for restricted (needsLimit) polymorphic query executing:
> **************************************************************************************
> int includedCount = -1;
> translator_loop: for ( int i = 0; i < translators.length; i++ ) {
> List tmp = translators[i].list( session, queryParametersToUse );
> if ( needsLimit ) {
> // NOTE : firstRow is zero-based
> int first = queryParameters.getRowSelection().getFirstRow() == null
> ? 0
> : queryParameters.getRowSelection().getFirstRow().intValue();
> int max = queryParameters.getRowSelection().getMaxRows() == null
> ? -1
> : queryParameters.getRowSelection().getMaxRows().intValue();
> final int size = tmp.size();
> for ( int x = 0; x < size; x++ ) {
> final Object result = tmp.get( x );
> if ( ! distinction.add( result ) ) {
> continue;
> }
> includedCount++;
> if ( includedCount < first ) {
> continue;
> }
> combinedResults.add( result );
> if ( max >= 0 && includedCount > max ) {
> // break the outer loop !!!
> break translator_loop;
> }
> }
> }
> else {
> combinedResults.addAll( tmp );
> }
> }
> **************************************************************************************
> or when I simplyfy the issue :
> int includedCount = -1;
> for ( int x = 0; x < size; x++ ) {
> final Object result = tmp.get( x );
> includedCount++;
> combinedResults.add( result );
> if ( max >= 0 && includedCount > max ) {
> // break the outer loop !!!
> break translator_loop;
> }
> }
> for example let start with max = 1;
> before for we start with includedCount = -1; x is undefined; combinedResults is empty;
> after 1. iteration: includedCount = 0; x = 0; combinedResults contains 1 item; test 'if ( max >= 0 && includedCount > max )' allows another iteration.
> after 2. iteration: includedCount = 1; x = 1; combinedResults contains 2 items; test 'if ( max >= 0 && includedCount > max )' allows another iteration.
> after 3. iteration: includedCount = 2; x = 2; combinedResults contains 3 items; test 'if ( max >= 0 && includedCount > max )' BREAKS another iteration.
> so we will finished with 3 items in combinedResults list, but requires only max = 1;
> **************************************************************************************
> And this is (I suppose) my problem of missing records (in next iteration in our PagedDataSource) :)
> It is correct ?
> Imrich Olha
> Ps. Sorry my bad english :(
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list