@RelatedTo(elementClass = Concept.class)RelatedTo.elementClass必须是一个类升

时间:2011-05-16 12:58:22

标签: java spring neo4j spring-data-graph

阅读此documentation,我尝试以这种方式应用于我的代码:

@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;
    }

概念

@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;
    }

我想要的用途在下面的图片中说明

enter image description here

然后,表三重将使用neo4j,概念将使用jpa和neo4j。我正在使用Eclipse IDE进行编程,它为我提供了纠正错误的建议。第一个是:

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

正确

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

然后,问题没有解决,并给了我nex消息

  

此行有多个标记      - 注释属性RelatedTo.elementClass的值必须是类   文字      - 类型安全:从Class到Class的未选中强制转换   NodeBacked&GT;      - 注释属性RelatedTo.elementClass的值必须是类   文字      - 类型安全:从Class到Class的未选中强制转换   NodeBacked&GT;

任何想法......我是新手,所以我很失落,我已经在春季论坛上问过,但没有成功。提前致谢

修改 我的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>

在eclipse中安装的软件 enter image description here

2 个答案:

答案 0 :(得分:1)

Spring Data使用一些编织技巧(aspectJ)来生成类。你必须在你的pom中添加一些插件,比如https://github.com/SpringSource/spring-data-graph-examples/blob/master/hello-worlds/pom.xml

答案 1 :(得分:1)

请使用此更新站点在您的eclipse IDE中安装AspectJ插件:

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

然后,您应该能够使用上下文菜单为项目启用AspectJ支持。

您的域类将被增强以实现NodeBacked接口,然后IDE将不会在注释或其他地方给您任何错误。

很抱歉这个混乱。我们将在下一版本中解决这些问题。

<强>更新

很抱歉我之前没有注意到,但是您放入elementClass的概念实际上是一个接口,因为它既没有使用@NodeEntity注释也没有扩展NodeBacked,这是真正的问题。

我想你也在春天提出问题forums,这里有我的建议:

您的Concept是一个界面,现在不会扩展NodeBacked。

通常:NodeBacked接口被添加到具有@NodeEntity注释的类中。

然后你可以尝试相同的解决方案。

  • 也可以使用@NodeEntity注释Concept。
  • 或者让Concept自身延伸NodeBacked

重要事项: elementClass应该参考具体实现(这可能适用于接口,因为它仅用于检查与目标的兼容性)。