Skip to content

Commit

Permalink
Fix eager batch collection not initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
dreab8 committed May 27, 2021
1 parent 21c607c commit f47a44e
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public Object[] getCollectionBatch(
}

if ( checkForEnd && i == end ) {
return resize( keys, i ); //the first key found after the given key
return keys; //the first key found after the given key
}

final boolean isEqual = collectionPersister.getKeyType().isEqual(
Expand All @@ -352,15 +352,7 @@ else if ( !isCached( ce.getLoadedKey(), collectionPersister ) ) {
}
}
}
return resize( keys, i ); //we ran out of keys to try
}

private Object[] resize(Object[] keys, int size) {
Object[] result = new Object[size];
for ( int i = 0; i < size; i++ ) {
result[i] = keys[i];
}
return result;
return keys; //we ran out of keys to try
}

private boolean isCached(Object collectionKey, CollectionPersister persister) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public PersistentCollection load(
new SingleIdLoadPlan( attributeMapping.getKeyDescriptor(), sqlAst, jdbcParameters ).load( key, LockOptions.READ, session );
}
else {
batchLoad( batchIds, session );
batchLoad( batchIds, numberOfIds , session );
}

final CollectionKey collectionKey = new CollectionKey( attributeMapping.getCollectionDescriptor(), key );
Expand All @@ -116,6 +116,7 @@ public PersistentCollection load(

private void batchLoad(
Object[] batchIds,
int numberOfIds,
SharedSessionContractImplementor session) {
if ( log.isDebugEnabled() ) {
log.debugf(
Expand All @@ -126,7 +127,7 @@ private void batchLoad(
}

int smallBatchStart = 0;
int smallBatchLength = Math.min( batchIds.length, batchSize );
int smallBatchLength = Math.min( numberOfIds, batchSize );

while ( true ) {
final List<JdbcParameter> jdbcParameters;
Expand All @@ -144,7 +145,7 @@ private void batchLoad(
null,
getLoadable().getKeyDescriptor(),
null,
batchIds.length,
numberOfIds,
session.getLoadQueryInfluencers(),
LockOptions.READ,
jdbcParameters::add,
Expand Down Expand Up @@ -209,11 +210,11 @@ public Callback getCallback() {

// prepare for the next round...
smallBatchStart += smallBatchLength;
if ( smallBatchStart >= batchIds.length ) {
if ( smallBatchStart >= numberOfIds ) {
break;
}

smallBatchLength = Math.min( batchIds.length - smallBatchStart, batchSize );
smallBatchLength = Math.min( numberOfIds - smallBatchStart, batchSize );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public Fetch generateFetch(
}
}

if ( getCollectionDescriptor().getCollectionType().hasHolder() ) {
if ( getCollectionDescriptor().getCollectionType().hasHolder() || !getCollectionDescriptor().isLazy() ) {
return new SelectEagerCollectionFetch( fetchablePath, this, fetchParent );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.hibernate.metamodel.internal.MetadataContext;
import org.hibernate.metamodel.model.domain.SetPersistentAttribute;
import org.hibernate.query.hql.spi.SqmCreationState;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.tree.SqmJoinType;
import org.hibernate.query.sqm.tree.domain.SqmSetJoin;
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void cleanupTest(EntityManagerFactoryScope scope) throws Exception {

@Test
@TestForIssue(jiraKey = "HHH-11144")
@FailureExpected( jiraKey = "HHH-11144" )
public void testInitializingSecondCollection(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.manytomany.batchload;
package org.hibernate.orm.test.manytomany.batchload;

import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -38,7 +38,7 @@
* @author Steve Ebersole
*/
@DomainModel(
xmlMappings = "org/hibernate/test/manytomany/batchload/UserGroupBatchLoad.hbm.xml"
xmlMappings = "org/hibernate/orm/test/manytomany/batchload/UserGroupBatchLoad.hbm.xml"
)
@SessionFactory(generateStatistics = true)
@ServiceRegistry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.manytomany.batchload;
package org.hibernate.orm.test.manytomany.batchload;
import java.util.HashSet;
import java.util.Set;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.test.manytomany.batchload;
package org.hibernate.orm.test.manytomany.batchload;

import org.hibernate.engine.jdbc.batch.internal.BatchBuilderImpl;
import org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.manytomany.batchload;
package org.hibernate.orm.test.manytomany.batchload;
import java.util.HashSet;
import java.util.Set;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">


<hibernate-mapping package="org.hibernate.test.manytomany.batchload">
<hibernate-mapping package="org.hibernate.orm.test.manytomany.batchload">

<class name="User" table="M2N_BATCHED_USER">
<id name="id" type="long">
Expand Down

0 comments on commit f47a44e

Please sign in to comment.