[hibernate-commits] Hibernate SVN: r16718 - core/branches/Branch_3_2/src/org/hibernate/loader.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Jun 8 12:05:08 EDT 2009


Author: steve.ebersole at jboss.com
Date: 2009-06-08 12:05:08 -0400 (Mon, 08 Jun 2009)
New Revision: 16718

Added:
   core/branches/Branch_3_2/src/org/hibernate/loader/MultipleBagFetchException.java
Modified:
   core/branches/Branch_3_2/src/org/hibernate/loader/BasicLoader.java
Log:
HHH-2980 - Error "org.hibernate.HibernateException: cannot simultaneously fetch multiple bags" not specific enough


Modified: core/branches/Branch_3_2/src/org/hibernate/loader/BasicLoader.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/loader/BasicLoader.java	2009-06-08 15:55:03 UTC (rev 16717)
+++ core/branches/Branch_3_2/src/org/hibernate/loader/BasicLoader.java	2009-06-08 16:05:08 UTC (rev 16718)
@@ -1,11 +1,13 @@
 //$Id$
 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 
@@ -45,13 +47,16 @@
 		}
 
 		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],
@@ -62,8 +67,8 @@
 		else {
 			collectionDescriptors = null;
 		}
-		if ( bagCount > 1 ) {
-			throw new HibernateException( "cannot simultaneously fetch multiple bags" );
+		if ( bagRoles != null && bagRoles.size() > 1 ) {
+			throw new MultipleBagFetchException( bagRoles );
 		}
 	}
 
@@ -75,13 +80,31 @@
 	 * 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.
+	 * <p/>
+	 * This form simply calls {@link #generateSuffixes(int, int) generateSuffixes(0,length}
+	 *
+	 * @param length The number of suffixes to generate
+	 *
+	 * @return The array of generated suffixes; the array length = length.
 	 */
 	public static String[] generateSuffixes(int length) {
 		return generateSuffixes( 0, length );
 	}
 
+	/**
+	 * Utility method that generates alias suffixes.
+	 *
+	 * @param seed The number from which to begin the suffix sequencing.  For example,
+	 * a seed of 0 would return 0_ as the first suffix; a seed of 5 would return 5_ as
+	 * the first suffix.
+	 * @param length The number of suffixes to generate
+	 *
+	 * @return The array of generated suffixes; the array length = length.
+	 */
 	public static String[] generateSuffixes(int seed, int length) {
-		if ( length == 0 ) return NO_SUFFIX;
+		if ( length == 0 ) {
+			return NO_SUFFIX;
+		}
 
 		String[] suffixes = new String[length];
 		for ( int i = 0; i < length; i++ ) {

Added: core/branches/Branch_3_2/src/org/hibernate/loader/MultipleBagFetchException.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/loader/MultipleBagFetchException.java	                        (rev 0)
+++ core/branches/Branch_3_2/src/org/hibernate/loader/MultipleBagFetchException.java	2009-06-08 16:05:08 UTC (rev 16718)
@@ -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;
+	}
+}




More information about the hibernate-commits mailing list