阅读本文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;
}
下图解释了我想要的用途
然后,表三元组将使用 neo4j,概念将使用 jpa 和 neo4j。我正在使用 Eclipse IDE 进行编程,它为我提供了纠正错误的建议。第一个是:
@RelatedTo(type = "conceptUriSubject", elementClass = Concept.class)
更正为
@RelatedTo(type = "conceptUriSubject", elementClass = (Class<? extends NodeBacked>) Concept.class)
然后,问题没有解决,并给了我下一条消息
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>
有什么想法吗?我对此很陌生,所以我很迷茫,我已经在 Spring 论坛上询问过,但没有成功。提前致谢
编辑
我的 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中安装的软件
最佳答案
请使用此更新站点在您的 eclipse IDE 中安装 AspectJ 插件:
http://download.eclipse.org/tools/ajdt/36/dev/update
然后您应该能够使用上下文菜单为您的项目启用 AspectJ 支持。
您的域类将得到增强以实现 NodeBacked 接口(interface),然后 IDE 不会在注释或其他地方给您任何错误。
抱歉造成困惑。我们将在下一个版本中解决这些问题。
更新:
抱歉,我之前没有注意到这一点,但是您放入 elementClass 中的概念实际上是一个接口(interface),因为它既没有用 @NodeEntity 注释,也没有扩展 NodeBacked,这才是真正的问题。
我想你在 Spring 也问过这个问题forums ,这是我的建议:
您的 Concept 是一个接口(interface),目前不扩展 NodeBacked。
一般来说:NodeBacked 接口(interface)被添加到具有 @NodeEntity 注释的类中。
那么您可以尝试相同的解决方案。
- 也可以使用 @NodeEntity 注释 Concept。
- 或者让 Concept 自行扩展 NodeBacked
重要提示: elementClass 应该引用具体实现(这可能适用于接口(interface),因为它只是用于检查与目标的兼容性)。
关于java - @RelatedTo(elementClass = Concept.class)RelatedTo.elementClass 必须是类升,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6017767/