Spring Data Commons
  1. Spring Data Commons
  2. DATACMNS-311

TypeDiscoverer fails to resolve properties expressed through read methods in supertypes

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.5.1, 1.6 M1
    • Component/s: Core
    • Labels:
      None

      Description

      interface Identifiable {
        String id;
      }
      
      interface Category extends Identifiable { }
      
      interface Product {
        Category category;
      }
      
      TypeInformation info = ClassTypeInformation.from(Product.class);
      assertThat(info.getProperty("category.id", is(notNullValue())));
      

      This fails as the PropertyDescriptor looked up in getPropertyInformation(…) is looked up for the direct type only, not inspecting super types.

        Issue Links

          Activity

          Hide
          Russell Morrisey added a comment -

          Hey,

          I just updated to the fix version, and it didn't resolve my problem. It seems like it could be a related issue.

          Event.java
          @Document(collection = "event")
          public class Event ... {
              private IKey key;
          
              @Override
              public AbstractKey getKey() {
                  return key;
              }
          }
          
          IKey.java
          public interface IKey {
              Collection<IAttribute> getAttributes();
          }
          

          Then I query:

              query.addCriteria(where("key.attributes").all(key.getAttributes()));
          

          (I am sure this query has other issues, I am still learning the API. However...)
          I get the following error:
          "No property attributes found on com.cscinfo.scheduler.domain.IKey"

          I walked through AbstractMappingContext in the debugger trying to understand what I did wrong, and I see that it finds the property on this line:

          BeanInfo info = Introspector.getBeanInfo(type);
          

          ...and then forgets about it on this line:

          ReflectionUtils.doWithFields(type, new PersistentPropertyCreator(entity, descriptors),
          						PersistentFieldFilter.INSTANCE);
          

          The interface type does not have an actual field which matches up to the property descriptor, so it "forgets" about this property descriptor.

          Show
          Russell Morrisey added a comment - Hey, I just updated to the fix version, and it didn't resolve my problem. It seems like it could be a related issue. Event.java @Document(collection = "event" ) public class Event ... { private IKey key; @Override public AbstractKey getKey() { return key; } } IKey.java public interface IKey { Collection<IAttribute> getAttributes(); } Then I query: query.addCriteria(where( "key.attributes" ).all(key.getAttributes())); (I am sure this query has other issues, I am still learning the API. However...) I get the following error: "No property attributes found on com.cscinfo.scheduler.domain.IKey" I walked through AbstractMappingContext in the debugger trying to understand what I did wrong, and I see that it finds the property on this line: BeanInfo info = Introspector.getBeanInfo(type); ...and then forgets about it on this line: ReflectionUtils.doWithFields(type, new PersistentPropertyCreator(entity, descriptors), PersistentFieldFilter.INSTANCE); The interface type does not have an actual field which matches up to the property descriptor, so it "forgets" about this property descriptor.
          Hide
          Russell Morrisey added a comment -

          There is a transcription error in the above comment; the getKey() method is supposed to return an IKey. I changed it to an abstract class in my latest code, in order to try to work around the problem.

          Show
          Russell Morrisey added a comment - There is a transcription error in the above comment; the getKey() method is supposed to return an IKey. I changed it to an abstract class in my latest code, in order to try to work around the problem.
          Hide
          Russell Morrisey added a comment -

          Verified that changing to 'AbstractKey' instead of 'IKey' let me work around this error. (My query semantics still aren't correct, but that's not relevant to the JIRA) I would really like to see it fixed, so I don't have to strip all of the interface usage off of my domain objects.

          Show
          Russell Morrisey added a comment - Verified that changing to 'AbstractKey' instead of 'IKey' let me work around this error. (My query semantics still aren't correct, but that's not relevant to the JIRA) I would really like to see it fixed, so I don't have to strip all of the interface usage off of my domain objects.

            People

            • Assignee:
              Oliver Gierke
              Reporter:
              Oliver Gierke
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: