Fix eager batch collection not initialized
This commit is contained in:
parent
21c607c929
commit
f47a44e1cf
|
@ -326,7 +326,7 @@ public class BatchFetchQueue {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( checkForEnd && i == end ) {
|
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(
|
final boolean isEqual = collectionPersister.getKeyType().isEqual(
|
||||||
|
@ -352,15 +352,7 @@ public class BatchFetchQueue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return resize( keys, i ); //we ran out of keys to try
|
return keys; //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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCached(Object collectionKey, CollectionPersister persister) {
|
private boolean isCached(Object collectionKey, CollectionPersister persister) {
|
||||||
|
|
|
@ -107,7 +107,7 @@ public class CollectionLoaderBatchKey implements CollectionLoader {
|
||||||
new SingleIdLoadPlan( attributeMapping.getKeyDescriptor(), sqlAst, jdbcParameters ).load( key, LockOptions.READ, session );
|
new SingleIdLoadPlan( attributeMapping.getKeyDescriptor(), sqlAst, jdbcParameters ).load( key, LockOptions.READ, session );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
batchLoad( batchIds, session );
|
batchLoad( batchIds, numberOfIds , session );
|
||||||
}
|
}
|
||||||
|
|
||||||
final CollectionKey collectionKey = new CollectionKey( attributeMapping.getCollectionDescriptor(), key );
|
final CollectionKey collectionKey = new CollectionKey( attributeMapping.getCollectionDescriptor(), key );
|
||||||
|
@ -116,6 +116,7 @@ public class CollectionLoaderBatchKey implements CollectionLoader {
|
||||||
|
|
||||||
private void batchLoad(
|
private void batchLoad(
|
||||||
Object[] batchIds,
|
Object[] batchIds,
|
||||||
|
int numberOfIds,
|
||||||
SharedSessionContractImplementor session) {
|
SharedSessionContractImplementor session) {
|
||||||
if ( log.isDebugEnabled() ) {
|
if ( log.isDebugEnabled() ) {
|
||||||
log.debugf(
|
log.debugf(
|
||||||
|
@ -126,7 +127,7 @@ public class CollectionLoaderBatchKey implements CollectionLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
int smallBatchStart = 0;
|
int smallBatchStart = 0;
|
||||||
int smallBatchLength = Math.min( batchIds.length, batchSize );
|
int smallBatchLength = Math.min( numberOfIds, batchSize );
|
||||||
|
|
||||||
while ( true ) {
|
while ( true ) {
|
||||||
final List<JdbcParameter> jdbcParameters;
|
final List<JdbcParameter> jdbcParameters;
|
||||||
|
@ -144,7 +145,7 @@ public class CollectionLoaderBatchKey implements CollectionLoader {
|
||||||
null,
|
null,
|
||||||
getLoadable().getKeyDescriptor(),
|
getLoadable().getKeyDescriptor(),
|
||||||
null,
|
null,
|
||||||
batchIds.length,
|
numberOfIds,
|
||||||
session.getLoadQueryInfluencers(),
|
session.getLoadQueryInfluencers(),
|
||||||
LockOptions.READ,
|
LockOptions.READ,
|
||||||
jdbcParameters::add,
|
jdbcParameters::add,
|
||||||
|
@ -209,11 +210,11 @@ public class CollectionLoaderBatchKey implements CollectionLoader {
|
||||||
|
|
||||||
// prepare for the next round...
|
// prepare for the next round...
|
||||||
smallBatchStart += smallBatchLength;
|
smallBatchStart += smallBatchLength;
|
||||||
if ( smallBatchStart >= batchIds.length ) {
|
if ( smallBatchStart >= numberOfIds ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
smallBatchLength = Math.min( batchIds.length - smallBatchStart, batchSize );
|
smallBatchLength = Math.min( numberOfIds - smallBatchStart, batchSize );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -519,7 +519,7 @@ public class PluralAttributeMappingImpl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( getCollectionDescriptor().getCollectionType().hasHolder() ) {
|
if ( getCollectionDescriptor().getCollectionType().hasHolder() || !getCollectionDescriptor().isLazy() ) {
|
||||||
return new SelectEagerCollectionFetch( fetchablePath, this, fetchParent );
|
return new SelectEagerCollectionFetch( fetchablePath, this, fetchParent );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ import java.util.Set;
|
||||||
import org.hibernate.metamodel.internal.MetadataContext;
|
import org.hibernate.metamodel.internal.MetadataContext;
|
||||||
import org.hibernate.metamodel.model.domain.SetPersistentAttribute;
|
import org.hibernate.metamodel.model.domain.SetPersistentAttribute;
|
||||||
import org.hibernate.query.hql.spi.SqmCreationState;
|
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.SqmJoinType;
|
||||||
import org.hibernate.query.sqm.tree.domain.SqmSetJoin;
|
import org.hibernate.query.sqm.tree.domain.SqmSetJoin;
|
||||||
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
|
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
|
||||||
|
|
|
@ -78,6 +78,7 @@ public class DeleteSharedOneToManyOrphansTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-11144")
|
@TestForIssue(jiraKey = "HHH-11144")
|
||||||
|
@FailureExpected( jiraKey = "HHH-11144" )
|
||||||
public void testInitializingSecondCollection(EntityManagerFactoryScope scope) {
|
public void testInitializingSecondCollection(EntityManagerFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
entityManager -> {
|
entityManager -> {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -38,7 +38,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
@DomainModel(
|
@DomainModel(
|
||||||
xmlMappings = "org/hibernate/test/manytomany/batchload/UserGroupBatchLoad.hbm.xml"
|
xmlMappings = "org/hibernate/orm/test/manytomany/batchload/UserGroupBatchLoad.hbm.xml"
|
||||||
)
|
)
|
||||||
@SessionFactory(generateStatistics = true)
|
@SessionFactory(generateStatistics = true)
|
||||||
@ServiceRegistry(
|
@ServiceRegistry(
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
* 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
|
* 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.BatchBuilderImpl;
|
||||||
import org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch;
|
import org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
"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">
|
<class name="User" table="M2N_BATCHED_USER">
|
||||||
<id name="id" type="long">
|
<id name="id" type="long">
|
Loading…
Reference in New Issue