[jbossseam-issues] [JBoss JIRA] Created: (JBSEAM-1892) org.jboss.seam.Entity constructor gets methods and fields from wrong instance.

Chris Rudd (JIRA) jira-events at lists.jboss.org
Sat Sep 1 00:47:29 EDT 2007


org.jboss.seam.Entity constructor gets methods and fields from wrong instance.
------------------------------------------------------------------------------

                 Key: JBSEAM-1892
                 URL: http://jira.jboss.com/jira/browse/JBSEAM-1892
             Project: JBoss Seam
          Issue Type: Bug
          Components: Core
    Affects Versions: 2.0.0.BETA1
            Reporter: Chris Rudd


The constructor for org.jboss.seam.Entity searches the fields and methods of an Entity class. The control loop uses "clazz" for the current class to be scanned, but the code in the for loops access getBeanClass(), so even thogh it checks each super class of the entity, each iteration gets the declared methods/fields from the beanClass.

Entity.java line 38

 public Entity(Class<?> beanClass)
   {
      super(beanClass);
      
      for ( Class<?> clazz=beanClass; clazz!=Object.class; clazz = clazz.getSuperclass() )
      {

-         for ( Method method: getBeanClass().getDeclaredMethods() )
+        for( Method method:clazz.getDeclaredMethods() )
         {
            //TODO: does the spec allow multiple lifecycle method
            //      in the entity class heirarchy?
            if ( method.isAnnotationPresent(PreRemove.class) )
            {
               preRemoveMethod = method;
            }
            if ( method.isAnnotationPresent(PrePersist.class) )
            {
               prePersistMethod = method;
            }
            if ( method.isAnnotationPresent(PreUpdate.class) )
            {
               preUpdateMethod = method;
            }
            if ( method.isAnnotationPresent(PostLoad.class) )
            {
               postLoadMethod = method;
            }
            if ( method.isAnnotationPresent(Id.class) || method.isAnnotationPresent(EmbeddedId.class))
            {
               identifierGetter = method;
            }
            if ( method.isAnnotationPresent(Version.class) )
            {
               versionGetter = method;
            }
            
            if ( !method.isAccessible() )
            {
               method.setAccessible(true);
            }
         }
         
         if (identifierGetter==null)
         {
-            for ( Field field: getBeanClass().getDeclaredFields() )
+           for ( Field field: clazz.getDeclaredFields() )
            {
               if ( field.isAnnotationPresent(Id.class) || field.isAnnotationPresent(EmbeddedId.class))
               {
                  identifierField = field;
                  if ( !field.isAccessible() )
                  {
                     field.setAccessible(true);
                  }
               }
               if ( field.isAnnotationPresent(Version.class) )
               {
                  versionField = field;
                  if ( !field.isAccessible() )
                  {
                     field.setAccessible(true);
                  }
               }
            }
         }
         
      }
      
   }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the seam-issues mailing list