HHH-2980 - Error "org.hibernate.HibernateException: cannot simultaneously fetch multiple bags" not specific enough

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@16717 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2009-06-08 15:55:03 +00:00
parent d68a7fe803
commit 838fcf9bae
2 changed files with 66 additions and 5 deletions

View File

@ -24,11 +24,13 @@
*/
package org.hibernate.loader;
import java.util.Set;
import java.util.HashSet;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.persister.entity.Loadable;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.type.BagType;
import org.hibernate.HibernateException;
/**
* Uses the default mapping from property to result set column
@ -68,13 +70,16 @@ public abstract class BasicLoader extends Loader {
}
CollectionPersister[] collectionPersisters = getCollectionPersisters();
int bagCount = 0;
Set bagRoles = null;
if ( collectionPersisters != null ) {
String[] collectionSuffixes = getCollectionSuffixes();
collectionDescriptors = new CollectionAliases[collectionPersisters.length];
for ( int i = 0; i < collectionPersisters.length; i++ ) {
if ( isBag( collectionPersisters[i] ) ) {
bagCount++;
if ( bagRoles == null ) {
bagRoles = new HashSet();
}
bagRoles.add( collectionPersisters[i].getRole() );
}
collectionDescriptors[i] = new GeneratedCollectionAliases(
collectionPersisters[i],
@ -85,8 +90,8 @@ public abstract class BasicLoader extends Loader {
else {
collectionDescriptors = null;
}
if ( bagCount > 1 ) {
throw new HibernateException( "cannot simultaneously fetch multiple bags" );
if ( bagRoles != null && bagRoles.size() > 1 ) {
throw new MultipleBagFetchException( bagRoles );
}
}
@ -98,6 +103,10 @@ public abstract class BasicLoader extends Loader {
* Utility method that generates 0_, 1_ suffixes. Subclasses don't
* necessarily need to use this algorithm, but it is intended that
* they will in most cases.
*
* @param length The number of suffixes to generate
*
* @return The array of generated suffixes (with length=length).
*/
public static String[] generateSuffixes(int length) {
return generateSuffixes( 0, length );

View File

@ -0,0 +1,52 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.loader;
import java.util.Set;
import org.hibernate.HibernateException;
/**
* Exception used to indicate that a query is attempting to simultaneously fetch multiple
* {@link org.hibernate.type.BagType bags}
*
* @author Steve Ebersole
*/
public class MultipleBagFetchException extends HibernateException {
private final Set bagRoles;
public MultipleBagFetchException(Set bagRoles) {
super( "cannot simultaneously fetch multiple bags" );
this.bagRoles = bagRoles;
}
/**
* Retrieves the set of collection roles for the bags encountered.
*
* @return The bag collection roles.
*/
public Set getBagRoles() {
return bagRoles;
}
}