Announcement Announcement Module
Collapse
No announcement yet.
Spring Data Graph: @Indexed on super type? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Data Graph: @Indexed on super type?

    Hello everyone

    I'm trying to use inheritance with SDG as follows:

    PHP Code:
    abstract public class NamedEntity {
        @
    Indexed
        
    private String name;

        
    NamedEntity(String name) {
            
    this.name name;
        }

        public 
    String getName() {
            return 
    name;
        }
    }

    @
    NodeEntity
    public class Person extends NamedEntity {
        ...

    I then get an IllegalArgumentException when I try to persist an instance of Person.
    Code:
    java.lang.IllegalArgumentException: Wrong index type supplied: class com.example.neo4j.domain.NamedEntity
    	at org.springframework.data.neo4j.support.GraphDatabaseContext.getIndex(GraphDatabaseContext.java:76)
    ....
    Is it possible to define an indexed property on a superclass? Are there other approaches?


    Best regards,
    James

  • #2
    Hey James,

    could you try to annotated your NamedEntity with @NodeEntity.

    The exception message doesn't make clear that it expects either a Node or a Relationship-Entity class as index class.

    I'll clean up the error message.

    HTH

    Michael

    Comment


    • #3
      Hi Michael

      Thanks - that worked!
      I'm quite sure that I also tried this. Sometimes I have the feeling that the aspectj compilation step is not done in eclipse when the source code is changed... Hm. But anyway. It works so far.


      Thank you,
      James

      Comment


      • #4
        That might be. I use IDEA or maven to do the AspectJ compilation. Sometimes like with interfaces you have to clean though. As the javac compiler doesn't see to get some dependent changes.

        I.e. doesn't recompile your entities when you changed something on a interface like NodeBacked.

        Glad it helped

        Michael

        Comment


        • #5
          Hi,

          can you use the findByPropertyValue("name", ..) Method on a GraphRepository<Person>?
          It seems to query the Person index only and doesnt return any results.

          Regards,
          Stefan

          Comment


          • #6
            What exactly do you want to use the findByPropertyValue method for?

            if it should work on a NamedEntity, you might try to create a repository for NamedEntity, or mix in the NamedIndexRepository into your repo, then you can use
            arbitrary index names in the method:

            T findByPropertyValue(String indexName, String property, Object value);

            HTH

            Michael

            Comment


            • #7
              I want to query a person by name via the GraphRepository<T>. Take the following example:

              PHP Code:
              GraphRepository<Personrepository = ..; // create via factory
              repository.save(new Person("Smith"));  // create a person
              Person p repository.findByPropertyValue("name""Smith"); // lookup person 
              Now the lookup does return null for me, since the Index for "name" does exist for the NamedEntity, but not for Person. Is that supposed to be like this?

              Regards,
              Stefan

              Comment


              • #8
                The Index name is created from the class where the actual @Indexed annotation is located.
                You can provide the @Indexed version with an index-name.

                I can look into using the most concrete, current class a source for the index name. Would probably make sense.

                Can you create a JIRA issue for that?

                Thanks

                Michael

                Comment


                • #9
                  Done: https://jira.springsource.org/browse/DATAGRAPH-98

                  Comment


                  • #10
                    I'm running into the same issue. Is there a workaround for this?

                    Comment


                    • #11
                      So far only using an explicit index name. Which would then be the same for all subclasses. Or push the field down to the actual domain classes.

                      Have quickly looked into the issue, the problem being that right now the current type (domain class) is not used at all at the internal, field-level API, so I have to change and extend that API for this to work.

                      As I'm going to rework this part anyway, it would be sensible to do that in the 1.2. timeframe using the Spring-Data-Commons mapping facilities (i.e. convenient analysis of reflection based meta-information of persistent types).

                      Comment


                      • #12
                        ractive:

                        There is a workaround, either you query the index manually or create a repository for the class which contains the property. See the testcase on the jira issue.

                        Regards,
                        Stefan

                        Comment


                        • #13
                          Thanks. I'm getting the index of the NamedEntity.class now manually and it seems to work.

                          Comment

                          Working...
                          X