[hibernate-commits] Hibernate SVN: r11217 - in branches/Branch_3_2/HibernateExt/annotations/src: test/org/hibernate/test/annotations/xml/ejb3 and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Feb 19 10:41:06 EST 2007


Author: epbernard
Date: 2007-02-19 10:41:06 -0500 (Mon, 19 Feb 2007)
New Revision: 11217

Modified:
   branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/reflection/EJB3OverridenAnnotationReader.java
   branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/xml/ejb3/orm.xml
Log:
EJB-271

Modified: branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/reflection/EJB3OverridenAnnotationReader.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/reflection/EJB3OverridenAnnotationReader.java	2007-02-19 15:08:01 UTC (rev 11216)
+++ branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/reflection/EJB3OverridenAnnotationReader.java	2007-02-19 15:41:06 UTC (rev 11217)
@@ -11,6 +11,8 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
 
 import javax.persistence.AssociationOverride;
 import javax.persistence.AssociationOverrides;
@@ -90,8 +92,11 @@
 import org.hibernate.annotations.common.reflection.AnnotationReader;
 import org.hibernate.annotations.common.reflection.Filter;
 import org.hibernate.annotations.common.reflection.ReflectionUtil;
+import org.hibernate.annotations.common.AssertionFailure;
 import org.hibernate.util.ReflectHelper;
 import org.hibernate.util.StringHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * Encapsulates the overriding of Java annotations from an EJB 3.0 descriptor.
@@ -101,6 +106,7 @@
  * @author Emmanuel Bernard
  */
 public class EJB3OverridenAnnotationReader implements AnnotationReader {
+	private static Log log = LogFactory.getLog( EJB3OverridenAnnotationReader.class );
 	private static final Map<Class, String> annotationToXml;
 	private static final String SCHEMA_VALIDATION = "Activate schema validation for more informations";
 	private static final Filter FILTER = new Filter() {
@@ -304,7 +310,8 @@
                 for (Annotation ann : this.annotations) {
                     annotationsMap.put( ann.annotationType(), ann );
                 }
-            }
+				checkForOrphanProperties(tree);
+			}
 			else if ( className != null ) { //&& propertyName != null ) { //always true but less confusing
 				Element tree = xmlContext.getXMLTree( className, propertyName );
 				Annotation[] annotations = getJavaAnnotations();
@@ -356,7 +363,43 @@
 		}
 	}
 
-    /**
+	private void checkForOrphanProperties(Element tree) {
+		Class clazz;
+		try {
+			clazz = ReflectHelper.classForName( className, this.getClass() );
+		}
+		catch (ClassNotFoundException e) {
+			throw new AssertionFailure("Unable to load class " + className );
+		}
+		Element element = tree != null ? tree.element( "attributes" ) : null;
+		//put entity.attributes elements
+		if ( element != null ) {
+			//precompute the list of properties
+			//TODO is it really useful...
+			Set<String> properties = new HashSet<String>();
+			for (Field field : clazz.getFields() ) {
+				properties.add( field.getName() );
+			}
+			for (Method method : clazz.getMethods() ) {
+				String name = method.getName();
+				if ( name.startsWith( "get" ) ) {
+					properties.add( Introspector.decapitalize( name.substring( "get".length() ) ) );
+				}
+				else if ( name.startsWith( "is" ) ) {
+					properties.add( Introspector.decapitalize( name.substring( "is".length() ) ) );
+				}
+			}
+			for ( Element subelement : (List<Element>) element.elements() ) {
+				String propertyName = subelement.attributeValue( "name" );
+				if ( ! properties.contains( propertyName ) ) {
+					log.warn("Property " + StringHelper.qualify( className, propertyName ) + " not found in class"
+							+ " but described in <mapping-file/> (possible typo error)");
+				}
+			}
+		}
+	}
+
+	/**
      * Addes the Annotation to the list (only if it's not null) and then returns it.
      */
     private Annotation addIfNotNull(List<Annotation> annotationList, Annotation element) {

Modified: branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/xml/ejb3/orm.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/xml/ejb3/orm.xml	2007-02-19 15:08:01 UTC (rev 11216)
+++ branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/xml/ejb3/orm.xml	2007-02-19 15:41:06 UTC (rev 11217)
@@ -24,6 +24,7 @@
                 <column name="fld_id"/>
                 <generated-value strategy="TABLE" generator="generator"/>
             </id>
+            <basic name="unknownProperty"/>
             <many-to-one name="manufacturer" fetch="LAZY">
                 <join-column name="manufacturer_pk"/>
             </many-to-one>




More information about the hibernate-commits mailing list