[hibernate-commits] Hibernate SVN: r18421 - in core/trunk/annotations/src: test/java/org/hibernate/test/annotations/indexcoll and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Jan 6 12:28:24 EST 2010


Author: epbernard
Date: 2010-01-06 12:28:23 -0500 (Wed, 06 Jan 2010)
New Revision: 18421

Modified:
   core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/indexcoll/AddressBook.java
Log:
HHH-4283 fix the incorrect test case and add a proper exception when the user error occurs

Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java	2010-01-06 17:01:04 UTC (rev 18420)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java	2010-01-06 17:28:23 UTC (rev 18421)
@@ -35,6 +35,7 @@
 import javax.persistence.ElementCollection;
 import javax.persistence.Embeddable;
 import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
 import javax.persistence.JoinTable;
 import javax.persistence.ManyToMany;
 import javax.persistence.MapKey;
@@ -464,6 +465,15 @@
 
 		//work on association
 		boolean isMappedBy = !BinderHelper.isDefault( mappedBy );
+
+		if (isMappedBy
+				&& (property.isAnnotationPresent( JoinColumn.class )
+					|| property.isAnnotationPresent( JoinTable.class ) ) ) {
+			String message = "Associations marked as mappedBy must not define database mappings like @JoinTable or @JoinColumn: ";
+			message += StringHelper.qualify( propertyHolder.getPath(), propertyName );
+			throw new AnnotationException( message );
+		}
+
 		collection.setInverse( isMappedBy );
 
 		//many to many may need some second pass informations
@@ -487,7 +497,7 @@
 				|| property.isAnnotationPresent( CollectionOfElements.class ) //legacy hibernate
 				|| property.isAnnotationPresent( ElementCollection.class ) //JPA 2
 				) {
-			// do it right away, otherwise @ManyToon on composite element call addSecondPass 
+			// do it right away, otherwise @ManyToOne on composite element call addSecondPass
 			// and raise a ConcurrentModificationException
 			//sp.doSecondPass( CollectionHelper.EMPTY_MAP );
 			mappings.addSecondPass( sp, !isMappedBy );

Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/indexcoll/AddressBook.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/indexcoll/AddressBook.java	2010-01-06 17:01:04 UTC (rev 18420)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/indexcoll/AddressBook.java	2010-01-06 17:28:23 UTC (rev 18421)
@@ -42,7 +42,6 @@
 
 	@MapKey
 	@OneToMany(mappedBy = "book", cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE})
-	@JoinTable(name="AddRegEntry")
 	public Map<AddressEntryPk, AddressEntry> getEntries() {
 		return entries;
 	}
@@ -63,7 +62,6 @@
 
 	@MapKey(name = "directory")
 	@OneToMany(mappedBy = "book")
-	@JoinTable(name="Dir_Entry")
 	public Map<AlphabeticalDirectory, AddressEntry> getDirectoryEntries() {
 		return directoryEntries;
 	}



More information about the hibernate-commits mailing list