[hibernate-commits] Hibernate SVN: r16717 - core/trunk/core/src/main/java/org/hibernate/loader.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Jun 8 11:55:03 EDT 2009


Author: steve.ebersole at jboss.com
Date: 2009-06-08 11:55:03 -0400 (Mon, 08 Jun 2009)
New Revision: 16717

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


Modified: core/trunk/core/src/main/java/org/hibernate/loader/BasicLoader.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/BasicLoader.java	2009-06-08 09:41:28 UTC (rev 16716)
+++ core/trunk/core/src/main/java/org/hibernate/loader/BasicLoader.java	2009-06-08 15:55:03 UTC (rev 16717)
@@ -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 @@
 		}
 
 		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 @@
 		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 @@
 	 * 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 );

Added: core/trunk/core/src/main/java/org/hibernate/loader/MultipleBagFetchException.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/MultipleBagFetchException.java	                        (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/loader/MultipleBagFetchException.java	2009-06-08 15:55:03 UTC (rev 16717)
@@ -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