From: <hib...@li...> - 2006-04-30 16:56:13
|
Author: epbernard Date: 2006-04-30 12:56:11 -0400 (Sun, 30 Apr 2006) New Revision: 9837 Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java Log: ANN-293 better user firendly error when annotations are wrongly used Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java =================================================================== --- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2006-04-30 16:44:28 UTC (rev 9836) +++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2006-04-30 16:56:11 UTC (rev 9837) @@ -14,6 +14,7 @@ import javax.persistence.ManyToMany; import javax.persistence.MapKey; import javax.persistence.OneToMany; +import javax.persistence.JoinTable; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -780,6 +781,24 @@ log.debug( "Binding a collection of element: " + path ); } } + //check for user error + if ( ! isCollectionOfEntities ) { + if ( property.isAnnotationPresent( ManyToMany.class ) || property.isAnnotationPresent( OneToMany.class )) { + String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName(); + throw new AnnotationException( + "Use of @OneToMany or @ManyToMany targeting an unmapped class: " + path + "[" + collType + "]" + ); + } + else { + JoinTable joinTableAnn = property.getAnnotation( JoinTable.class ); + if (joinTableAnn != null && joinTableAnn.inverseJoinColumns().length > 0) { + String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName(); + throw new AnnotationException( + "Use of @JoinTable.inverseJoinColumns targeting an unmapped class: " + path + "[" + collType + "]" + ); + } + } + } boolean mappedBy = ! AnnotationBinder.isDefault( joinColumns[0].getMappedBy() ); if ( mappedBy ) { if ( ! isCollectionOfEntities ) { |