[hibernate-commits] Hibernate SVN: r14417 - annotations/trunk/src/java/org/hibernate/cfg/annotations.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Mar 10 19:51:07 EDT 2008


Author: epbernard
Date: 2008-03-10 19:51:06 -0400 (Mon, 10 Mar 2008)
New Revision: 14417

Modified:
   annotations/trunk/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
Log:
ANN-701 Better error message when @CollectionId is used on wrong collection types

Modified: annotations/trunk/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/annotations/CollectionBinder.java	2008-03-10 03:26:11 UTC (rev 14416)
+++ annotations/trunk/src/java/org/hibernate/cfg/annotations/CollectionBinder.java	2008-03-10 23:51:06 UTC (rev 14417)
@@ -203,15 +203,31 @@
 			//TODO consider using an XClass
 			Class returnedClass = property.getCollectionClass();
 			if ( java.util.Set.class.equals( returnedClass ) ) {
+				if ( property.isAnnotationPresent( CollectionId.class ) ) {
+					throw new AnnotationException( "Set do not support @CollectionId: "
+							+ StringHelper.qualify( entityName, property.getName() ) );
+				}
 				return new SetBinder();
 			}
 			else if ( java.util.SortedSet.class.equals( returnedClass ) ) {
+				if ( property.isAnnotationPresent( CollectionId.class ) ) {
+					throw new AnnotationException( "Set do not support @CollectionId: "
+							+ StringHelper.qualify( entityName, property.getName() ) );
+				}
 				return new SetBinder( true );
 			}
 			else if ( java.util.Map.class.equals( returnedClass ) ) {
+				if ( property.isAnnotationPresent( CollectionId.class ) ) {
+					throw new AnnotationException( "Map do not support @CollectionId: "
+							+ StringHelper.qualify( entityName, property.getName() ) );
+				}
 				return new MapBinder();
 			}
 			else if ( java.util.SortedMap.class.equals( returnedClass ) ) {
+				if ( property.isAnnotationPresent( CollectionId.class ) ) {
+					throw new AnnotationException( "Map do not support @CollectionId: "
+							+ StringHelper.qualify( entityName, property.getName() ) );
+				}
 				return new MapBinder( true );
 			}
 			else if ( java.util.Collection.class.equals( returnedClass ) ) {
@@ -224,6 +240,10 @@
 			}
 			else if ( java.util.List.class.equals( returnedClass ) ) {
 				if ( isIndexed ) {
+					if ( property.isAnnotationPresent( CollectionId.class ) ) {
+						throw new AnnotationException( "List do not support @CollectionId and @IndexColumn at the same time: "
+								+ StringHelper.qualify( entityName, property.getName() ) );
+					}
 					return new ListBinder();
 				}
 				else if ( property.isAnnotationPresent( CollectionId.class ) ) {




More information about the hibernate-commits mailing list