Announcement Announcement Module
Collapse
No announcement yet.
SDG: Relationships w/ Generified Types? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SDG: Relationships w/ Generified Types?

    Hi all-

    I am doing a spike w/ Spring Data Graph of an implementation of the "Entity-Attribute-Value" pattern. We have built an application of this nature using a relational database, and at first glance at the graph DB abstraction, it is a better fit.

    So...I have created an Entity class as such:

    Code:
    @NodeEntity
    public class Entity {
    
       @RelatedTo(type = "HAS_ATTRIBUTE", elementClass = Attribute.class)
       private Set<Attribute> attributes;
    
       //...leaving out getter/setter
    }
    and Attribute class:

    Code:
    @NodeEntity
    public class Attribute<T> {
    
       @Indexed
       private T value;
    
       //..leaving out getter/setter
    }
    Here's a test method:

    Code:
    @Test
    public void exploreAddingStringAttribute() {
    	
       Entity entity = new Entity();
       entity.setType(Entity.Type.SUBJECT); //I omitted this property from the code pasted in!
       entity.persist();
    		
       Attribute<String> sampleType = new Attribute<String>("DNA");
       sampleType.persist();
       entity.addAttribute(sampleType);
    		
       Assert.assertEquals(1, entity.getAttributes().size());
    }
    This test fails w/ a NullPointerException:

    Code:
    java.lang.NullPointerException
    	at org.springframework.data.graph.neo4j.support.node.Neo4jNodeBacking.ajc$interMethod$org_springframework_data_graph_neo4j_support_node_Neo4jNodeBacking$org_springframework_data_graph_core_NodeBacked$persist(Neo4jNodeBacking.aj:120)
    	at org.stjude.srm.datagraph.Attribute.persist(Attribute.java:1)
    	at org.springframework.data.graph.neo4j.support.node.Neo4jNodeBacking.ajc$interMethodDispatch1$org_springframework_data_graph_neo4j_support_node_Neo4jNodeBacking$org_springframework_data_graph_core_NodeBacked$persist(Neo4jNodeBacking.aj)
    	at org.stjude.srm.datagraph.EntityTest.exploreAddingStringAttribute(EntityTest.java:35)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	...
    Shortly after writing this code my guess was that I'm running into type erasure. But perhaps I'm just misunderstanding how this whole deal is working. I don't know - that's why I'm here! :-)

    Assuming this is the wrong way to do what I want, which is to have a Entity w/ a Set of Attributes that are strongly-typed and of variable types (perhaps Attribute<String>, Attribute<Integer>, Attribute<Date>, ...), what would be the recommended path?

    Thanks,

    Matt

  • #2
    Matt,

    thanks for get
    can you also provide your spring config, otherwise it looks good.

    And please the implementation of the addAttribute method (it could be either attribues.add, or relateTo(attribute,"HAS_ATTRIBUTE") which is more efficient for big sets of attributes.

    Thanks

    Michael

    Comment


    • #3
      Code in GitHub

      Michael-

      Thanks for your response. Tell you what - to make this easier, I've just included the entire project in GitHub. It is built w/ Gradle. Please take a look:

      https://github.com/mstine/spr-data-graph-spike

      Thanks!

      Matt

      Comment


      • #4
        Matt,

        thanks for the project, that really helped with identifying the problem, it seems that the current pointcut for advising entity construction doesn't seem to catch generic types. I'll follow up with Andy Clement the AJ project lead on that.

        Can you go with concrete types until the issue is resolved?

        Cheers

        Michael

        Comment


        • #5
          Michael-

          That was my diagnosis as well. That said, I'm certainly no AspectJ expert, so I thought I'd wait for your thoughts.

          I really need to use the generified types for this particular object model as it keeps things very clean. So, for the time being I am building my own facade to the Neo4J API directly. It should be relatively easy to swap back to SDG at a later date. My hope is that this will be soon, as it will eliminate a lot of code.

          Thanks again!

          Matt

          Comment


          • #6
            Andy Clement confirmed that this is a bug in AJ in the handling of complex generified aspects. It is fixed in aspectj-1.6.12-BUILD-SNAPSHOT, if you want to try this you are more than welcome.

            Thanks again

            Michael

            Comment


            • #7
              Success!

              Nice..my tests are passing after introducing this snapshot build of AspectJ.

              I will continue down this path a bit and see where things go.

              Thanks!

              Matt

              Comment

              Working...
              X