Announcement Announcement Module
Collapse
No announcement yet.
SDG: @RelatedTo elementClass question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SDG: @RelatedTo elementClass question

    I've noticed in some cases I can have relationships that are interfaces, while in others SDG doesn't seem to be able to determine the FieldAccessor unless I use the implementation. Here's an example:

    Code:
    @NodeEntity
    public class AclEntryImpl implements AclEntry
    {
      @RelatedTo(type = "ACLENTRY_PRINCIPAL", elementClass = PrincipalImpl.class)
      private Principal user;
      @RelatedTo(type = "PERMISSION", elementClass = PermissionImpl.class)
      private Set<Permission> permissionSet = new HashSet<Permission>(10, 10);
      private boolean negative = false;
    }
    produces the following warning related to the 'user' property...

    Code:
    Apr 21, 2011 8:01:25 AM org.springframework.data.graph.neo4j.fieldaccess.DelegatingFieldAccessorFactory factoryForField
    WARNING: No FieldAccessor configured for field: private java.security.Principal org.mycompany.graph.model.acl.AclEntryImpl.user
    But the 'permissionSet' property is set correctly, even through it is using the Permission interface, not the PermissionImpl...

    Code:
    Apr 21, 2011 8:01:25 AM org.springframework.data.graph.neo4j.fieldaccess.DelegatingFieldAccessorFactory factoryForField
    INFO: Factory org.springframework.data.graph.neo4j.fieldaccess.OneToNRelationshipFieldAccessorFactory@15d616e used for field: private java.util.Set org.mycompany.graph.model.acl.AclEntryImpl.permissionSet
    When I change the 'user' property to the implementation of Principal, no more warnings:

    Code:
    @NodeEntity
    public class AclEntryImpl implements AclEntry
    {
      @RelatedTo(type = "ACLENTRY_PRINCIPAL", elementClass = PrincipalImpl.class)
      private PrincipalImpl user;
      @RelatedTo(type = "PERMISSION", elementClass = PermissionImpl.class)
      private Set<Permission> permissionSet = new HashSet<Permission>(10, 10);
      private boolean negative = false;
    }
    no more warnings...

    Code:
    Apr 21, 2011 8:07:37 AM org.springframework.data.graph.neo4j.fieldaccess.DelegatingFieldAccessorFactory factoryForField
    INFO: Factory org.springframework.data.graph.neo4j.fieldaccess.SingleRelationshipFieldAccessorFactory@1cfb802 used for field: private org.mycompany.graph.model.acl.PrincipalImpl org.mycompany.graph.model.acl.AclEntryImpl.user

    Why can't I use the Principal interface for this property? I would think the 'elementClass = PrincipalImpl.class' directive should give SDG enough info to work with.

  • #2
    UPDATE: This only seems to be the case in 1:1 relationships. In all my other tests where the cardinality was 1:N, there was no issue using the interface:

    Code:
    @RelateTo(type="PERMISSION", elementClass=PermissionImpl.class)
    Set<Permission> permissions;  //works and is detected by SDG
    @RelatedTo(type = "ACLENTRY_PRINCIPAL", elementClass = PrincipalImpl.class)
    private Principal user; //doesn't works and isn't detected by SDG

    Comment


    • #3
      UPDATE: Despite the warning message, everything seems to work OK. I would still ask why is the warning being displayed. In case someone wishes to investigate, I've attached sample model that produces the following warning:

      Code:
      Apr 23, 2011 9:23:45 PM org.springframework.data.graph.neo4j.fieldaccess.DelegatingFieldAccessorFactory factoryForField
      WARNING: No FieldAccessor configured for field: private org.mycompany.graph.model.DomainObject1Interface org.mycompany.graph.model.DomainObject2.domainObject

      Comment


      • #4
        Thanks for the investigation sorry forgot to answer this thread despite reading it
        Will look at your sample and report back.

        Michael

        Comment


        • #5
          As SDG takes the class given there to create the actual instance (or at least verify it with the type stored in the graph depending on the type representation strategy) it is not possible to use just the interface. Sorry for that, we might loosen that constraint (or eliminate the necessity to provide the elementClass at all) in future releases.

          Thanks Michael

          Comment


          • #6
            Curious why the persistence works anyway when I use the interface, despite the warning message. Also why is there no warning for instances where I use the interface in a set (see second thread in this topic for an example of this).

            Comment


            • #7
              The warning for the interface is just missing in the set path.

              It works because it returns instances of the type stored in the graph. The generic type of the set is not used at all.

              The type check actually doesn't check for type equality but for elementClass.isAssignableFrom(concreteTypeClassFro mGraph).

              Not sure how to proceed from the current situation, perhaps just loosen the constraint to allow interfaces (as long as there is type information stored in the graph that can be used).

              Cheers

              Michael

              Comment

              Working...
              X