Buggy code:
public class JDBCStoreQuery extends ExpressionStoreQuery { private static final Table INVALID = new Table ( ) ; private static final Map _listeners = new HashMap ( ) ; private final transient JDBCStore _store ; public JDBCStoreQuery ( JDBCStore store , ExpressionParser parser ) { } public JDBCStore getStore ( ) { } public FilterListener getFilterListener ( String tag ) { } public Object newCompilationKey ( ) { } public boolean supportsDataStoreExecution ( ) { } protected ClassMetaData [ ] getIndependentExpressionCandidates ( ClassMetaData meta , boolean subclasses ) { } protected ExpressionFactory getExpressionFactory ( ClassMetaData meta ) { } protected ResultObjectProvider executeQuery ( Executor ex , ClassMetaData base , ClassMetaData [ ] metas , boolean subclasses , ExpressionFactory [ ] facts , QueryExpressions [ ] exps , Object [ ] params , boolean lrs , long startIdx , long endIdx ) { <START_BUG> if ( ( ( metas . length ) > 1 ) && ( exps [ 0 ] . aggregate ) ) <END_BUG> throw new org . apache . openjpa . util . UserException ( Localizer . forPackage ( JDBCStoreQuery . class ) . get ( "mult-mapping-aggregate" , Arrays . asList ( metas ) ) ) ; ClassMapping [ ] mappings = ( ( ClassMapping [ ] ) ( metas ) ) ; JDBCFetchConfiguration fetch = ( ( JDBCFetchConfiguration ) ( ctx . getFetchConfiguration ( ) ) ) ; if ( ( exps [ 0 ] . fetchPaths ) != null ) { fetch . addFields ( Arrays . asList ( exps [ 0 ] . fetchPaths ) ) ; fetch . addJoins ( Arrays . asList ( exps [ 0 ] . fetchPaths ) ) ; } int eager = calculateEagerMode ( exps [ 0 ] , startIdx , endIdx ) ; int subclassMode = fetch . getSubclassFetchMode ( ( ( ClassMapping ) ( base ) ) ) ; DBDictionary dict = _store . getDBDictionary ( ) ; long start = ( ( ( mappings . length ) == 1 ) && ( dict . supportsSelectStartIndex ) ) ? startIdx : 0L ; long end = ( dict . supportsSelectEndIndex ) ? endIdx : Long . MAX_VALUE ; List sels = new ArrayList ( mappings . length ) ; List selMappings = new ArrayList ( mappings . length ) ; BitSet subclassBits = new BitSet ( ) ; BitSet nextBits = new BitSet ( ) ; boolean unionable = ( ( ( createWhereSelects ( sels , mappings , selMappings , subclasses , subclassBits , nextBits , facts , exps , params , fetch , subclassMode ) ) && ( subclassMode == ( JDBCFetchConfiguration . EAGER_JOIN ) ) ) && ( start == 0 ) ) && ( end == ( Long . MAX_VALUE ) ) ; if ( ( sels . size ( ) ) > 1 ) start = 0L ; lrs = lrs || ( ( ( fetch . getFetchBatchSize ( ) ) >= 0 ) && ( ( start != startIdx ) || ( end != endIdx ) ) ) ; ResultObjectProvider [ ] rops = null ; ResultObjectProvider rop = null ; if ( unionable ) { Union union = _store . getSQLFactory ( ) . newUnion ( ( ( Select [ ] ) ( sels . toArray ( new Select [ sels . size ( ) ] ) ) ) ) ; BitSet [ ] paged = populateUnion ( union , mappings , subclasses , facts , exps , params , fetch , lrs , eager , start , end ) ; union . setLRS ( lrs ) ; rop = executeUnion ( union , mappings , exps , paged , fetch ) ; } else { if ( ( sels . size ( ) ) > 1 ) rops = new ResultObjectProvider [ sels . size ( ) ] ; Select sel ; BitSet paged ; for ( int i = 0 , idx = 0 ; i < ( sels . size ( ) ) ; i ++ ) { sel = ( ( Select ) ( sels . get ( i ) ) ) ; paged = populateSelect ( sel , ( ( ClassMapping ) ( selMappings . get ( i ) ) ) , subclassBits . get ( i ) , ( ( JDBCExpressionFactory ) ( facts [ idx ] ) ) , exps [ idx ] , params , fetch , lrs , eager , start , end ) ; rop = executeSelect ( sel , ( ( ClassMapping ) ( selMappings . get ( i ) ) ) , exps [ idx ] , paged , fetch , start , end ) ; if ( rops != null ) rops [ i ] = rop ; if ( nextBits . get ( i ) ) idx ++ ; } } if ( rops != null ) { if ( ( exps [ 0 ] . ascending . length ) == 0 ) rop = new org . apache . openjpa . lib . rop . MergedResultObjectProvider ( rops ) ; else { rop = new org . apache . openjpa . kernel . OrderingMergedResultObjectProvider ( rops , exps [ 0 ] . ascending , ex , this , params ) ; } } if ( ( ( ( rops != null ) && ( endIdx != ( Long . MAX_VALUE ) ) ) || ( start != startIdx ) ) || ( end != endIdx ) ) rop = new org . apache . openjpa . lib . rop . RangeResultObjectProvider ( rop , startIdx , endIdx ) ; return rop ; } private BitSet [ ] populateUnion ( Union union , final ClassMapping [ ] mappings , final boolean subclasses , final ExpressionFactory [ ] facts , final QueryExpressions [ ] exps , final Object [ ] params , final JDBCFetchConfiguration fetch , final boolean lrs , final int eager , final long start , final long end ) { }

Fix:
if ( ( ( metas . length ) > 1 ) && ( exps [ 0 ] . isAggregate ( ) ) )