0

Reading this documentation, I tryed to apply to my code in this way:

Triple

@Entity
@Table(name = "triple")
@NodeEntity
public class TripleDBMoldelNeoImpl implements TripleDBModel{
    protected List<Annotation> annotations;

    @RelatedTo(type = "subject", elementClass = (Class<? extends NodeBacked>) Concept.class) //This is the suggestion Eclipse gives me
    public Concept subject;
    @RelatedTo(type = "object", elementClass = Concept.class)
    public Concept object;
    @RelatedTo(type = "predicate", elementClass = Concept.class)
    public Concept predicate;


    @ManyToMany(
            cascade={CascadeType.ALL }, 
            fetch=FetchType.LAZY
    )   
    @JoinTable(name = "triple_has_annotation", 
            joinColumns={@JoinColumn(name="uri_concept_subject"), @JoinColumn(name="uri_concept_object"), @JoinColumn(name="uri_concept_predicate") },          
            inverseJoinColumns=@JoinColumn(name="annotation_id") )
    public List<Annotation> getAnnotations() {
        return annotations;
    }
    public void setAnnotations(List<Annotation> annotations) {
        this.annotations = annotations;
    }
    @Id 
    @Column(name = "subject", length = 100)
    public Concept getSubject() {
        return subject;
    }
    public void setSubject(Concept subject) {
        this.subject = subject;
    }

    @Id 
    @Column(name = "object", length = 100)
    public Concept getObject() {
        return object;
    }
    public void setObject(Concept object) {
        this.object = object;
    }
    @Id 
    @Column(name = "predicate", length = 100)
    public Concept getPredicate() {
        return predicate;
    }
    public void setPredicate(Concept predicate) {
        this.predicate = predicate;
    }

Concept

@NodeEntity(partial = true)
public class ConceptNeoImpl implements java.io.Serializable, Concept {

    private static final long serialVersionUID = 1L;
    private String uri;
    private String label;
    private String ontologyElement;
    private List<Annotation> annotations;
    @RelatedTo(type = "conceptSub", elementClass = TripleDBModel.class)
    private TripleDBModel triple;

    public TripleDBModel getTriple() {
        return triple;
    }

    public void setTriple(TripleDBModel triple) {
        this.triple = triple;
    }

The use I want to is explained on the image below

enter image description here

Then, the table triple will be using neo4j and concept will be using jpa and neo4j. I am programming using Eclipse IDE and it gives me suggestions to correct the errors. The first one is:

@RelatedTo(type = "conceptUriSubject", elementClass = Concept.class)

correct to

@RelatedTo(type = "conceptUriSubject", elementClass = (Class<? extends NodeBacked>) Concept.class)

And then, the problem is not solved, and gives me the nex message

Multiple markers at this line - The value for annotation attribute RelatedTo.elementClass must be a class literal - Type safety: Unchecked cast from Class to Class NodeBacked> - The value for annotation attribute RelatedTo.elementClass must be a class literal - Type safety: Unchecked cast from Class to Class NodeBacked>

Any ideas¿¿ I am new on this, so I am quite lost and I already asked on spring forums, with no success. Thanks in advance

EDIT Plugins on my pom.xml

<plugins>
          <plugin>
            <!-- Execute the main class -->
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>exec</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <mainClass>org.springframework.data.neo4j.examples.hellograph.App</mainClass>
            </configuration>
          </plugin>
          <plugin>
            <!-- IntelliJ Idea Support -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-idea-plugin</artifactId>
            <version>2.2</version>
            <configuration>
              <downloadSources>true</downloadSources>
              <dependenciesAsLibraries>true</dependenciesAsLibraries>
            </configuration>
          </plugin>



            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.0</version>
                <dependencies>
                    <!-- NB: You must use Maven 2.0.9 or above or these are ignored (see 
                        MNG-2972) -->
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjrt</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjtools</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <outxml>true</outxml>
                    <aspectLibraries>
                        <aspectLibrary>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-aspects</artifactId>
                        </aspectLibrary>
                        <aspectLibrary>
                            <groupId>org.springframework.data</groupId>
                            <artifactId>spring-data-neo4j</artifactId>
                        </aspectLibrary>
                    </aspectLibraries>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

        </plugins>

Software installed in eclipse enter image description here

Andrey Agibalov
  • 7,624
  • 8
  • 66
  • 111
Blanca Hdez
  • 3,513
  • 19
  • 71
  • 93

2 Answers2

1

Spring Data uses some weaving tricks (aspectJ) to generate classes. You have to add some plugin in your pom, like https://github.com/SpringSource/spring-data-graph-examples/blob/master/hello-worlds/pom.xml

Vincent Devillers
  • 1,628
  • 1
  • 11
  • 17
  • I have just edited my question, showing the plugins I have on my pom.xml The one I had left before is exec-maven-plugin and maven-idea-plugin. But the error is the same after uploading dependencies – Blanca Hdez May 16 '11 at 14:39
  • you are using an idea plugin (maven-idea-plugin), but you need the eclipse plugin – Vincent Devillers May 16 '11 at 14:58
1

Please install the AspectJ Plugin in your eclipse IDE using this update site:

http://download.eclipse.org/tools/ajdt/36/dev/update

Then you should be able to enable AspectJ support for your project using the context menu.

Your domain class will be enhanced to implement the NodeBacked interface and then the IDE won't give you any errors in the annotations or elsewhere.

Sorry for the confusion. We are going to address those issues in the next release.

Update:

Sorry I didn't notice that earlier but the Concept you put into the elementClass is actually an interface and as it is neither annotated with @NodeEntity nor extending NodeBacked this is the real problem.

I think you also asked the question in the Spring forums, here are my suggestions from there:

Your Concept is an interface and does not extend NodeBacked right now.

In general: the NodeBacked interface is added to classes that have the @NodeEntity annotation.

Then you might try the same solution.

  • either annotate Concept with @NodeEntity too.
  • or have Concept extend NodeBacked on itself

Important: elementClass should rather refer to the concrete implementation (this might work with the interface though as it is just used to check for compatibility with the target).

Michael Hunger
  • 41,339
  • 3
  • 57
  • 80
  • I have installed in eclipse, using Help-install new software, adding the site you said, but I have still the same error. I added a screenshot with the software installed on my eclipse IDE. Thanks – Blanca Hdez May 17 '11 at 07:47
  • I want to set it up to use it with maven, not just in eclipse. Therefore, I followed the documentation (I think you are one of the authors) http://static.springsource.org/spring-data/data-graph/docs/current/reference/html/#d0e979 and in 20.1.3 But I can not even make a package. Any help would ve apreciated – Blanca Hdez May 17 '11 at 08:41
  • I have realized that I can compile the project, even with these errors. It is a bit anoying but at least it doesn't block the work – Blanca Hdez May 17 '11 at 12:45