gpt4 book ai didi

java - 从 Annotation 引用 Triple 的外键具有错误的列数。

转载 作者:行者123 更新时间:2023-11-29 06:14:24 25 4
gpt4 key购买 nike

虽然我对此做了一些研究,并且发现了很多在互联网上开放的威胁,但我无法解决我的问题。我附上我的代码:

Triple.java 主键由来自三个不同概念的3个URI组成,但它是同一列(这是一个问题吗?)

        @Entity
@IdClass(ConceptPk.class)
@Table(name = "triple")
public class TripleDBModel {

protected List<Annotation> annotations;
public String conceptUriSubject;
public String conceptUriObject;
public String conceptUriPredicate;
public String id;



@ManyToMany(
cascade={CascadeType.ALL},
fetch=FetchType.LAZY
)
@JoinTable(name = "triple_has_annotation",
joinColumns=@JoinColumn(name="annotation_id"),
inverseJoinColumns={@JoinColumn(name="uri_concept_subject", referencedColumnName="triple_id"), @JoinColumn(name="uri_concept_object", referencedColumnName="triple_id"), @JoinColumn(name="uri_concept_predicate", referencedColumnName="triple_id")
})//EDIT
public List<Annotation> getAnnotations() {
return annotations;
}
public void setAnnotations(List<Annotation> annotations) {
this.annotations = annotations;
}
@Id
@Column(name = "uri_concept_subject", length = 100)
public String getConceptUriSubject() {
return conceptUriSubject;
}
public void setConceptUriSubject(String conceptUriSubject) {
this.conceptUriSubject = conceptUriSubject;
}
@Id
@Column(name = "uri_concept_object", length = 100)
public String getConceptUriObject() {
return conceptUriObject;
}
public void setConceptUriObject(String conceptUriObject) {
this.conceptUriObject = conceptUriObject;
}
@Id
@Column(name = "uri_concept_predicate", length = 100)
public String getConceptUriPredicate() {
return conceptUriPredicate;
}
public void setConceptUriPredicate(String conceptUriPredicate) {
this.conceptUriPredicate = conceptUriPredicate;
}

@Id
@Column(name = "triple_id", unique = true, nullable = false)
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}

ConceptPk.java

    @Embeddable
public class ConceptPk implements java.io.Serializable {

private static final long serialVersionUID = 1L;
public String conceptUriSubject;
public String conceptUriObject;
public String conceptUriPredicate;

@Id
@Column(name = "uri", length = 100, unique = true, nullable = false)
public String getConceptUriSubject() {
return conceptUriSubject;
}
public void setConceptUriSubject(String conceptUriSubject) {
this.conceptUriSubject = conceptUriSubject;
}

@Id
@Column(name = "uri", length = 100, unique = true, nullable = false)
public String getConceptUriObject() {
return conceptUriObject;
}
public void setConceptUriObject(String conceptUriObject) {
this.conceptUriObject = conceptUriObject;
}

@Id
@Column(name = "uri", length = 100, unique = true, nullable = false)
public String getConceptUriPredicate() {
return conceptUriPredicate;
}
public void setConceptUriPredicate(String conceptUriPredicate) {
this.conceptUriPredicate = conceptUriPredicate;
}

注释.java

    @Entity
@Table(name = "annotations")
public class Annotation {

private Integer id;
private List<TripleDBModel> triples;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "annotation_id", unique = true, nullable = false)
public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

@ManyToMany(
cascade={CascadeType.ALL},
mappedBy = "annotations", //EDIT
fetch=FetchType.LAZY
)
public List<TripleDBModel> getTriples() {
return triples;
}

public void setTriples(List<TripleDBModel> triples) {
this.triples = triples;
}

但是我得到了这个错误:

Caused by: org.hibernate.AnnotationException: A Foreign key refering TripleDBModel from Annotation has the wrong number of column. should be 3

我做错了什么??提前致谢

最佳答案

最终的解决方案是:

ConceptPk.java

@Embeddable
public class ConceptPk implements java.io.Serializable {

private static final long serialVersionUID = 1L;
public Concept conceptUriSubject;
public Concept conceptUriObject;
public Concept conceptUriPredicate;

@Id
@ManyToOne(cascade=CascadeType.MERGE)
@JoinColumn(name="uri_concept_subject")
public Concept getConceptUriSubject() {
return conceptUriSubject;
}
public void setConceptUriSubject(Concept conceptUriSubject) {
this.conceptUriSubject = conceptUriSubject;
}

@Id
@ManyToOne(cascade=CascadeType.MERGE)
@JoinColumn(name="uri_concept_object")
public Concept getConceptUriObject() {
return conceptUriObject;
}
public void setConceptUriObject(Concept conceptUriObject) {
this.conceptUriObject = conceptUriObject;
}

@Id
@ManyToOne(cascade=CascadeType.MERGE)
@JoinColumn(name="uri_concept_predicate")
public Concept getConceptUriPredicate() {
return conceptUriPredicate;
}
public void setConceptUriPredicate(Concept conceptUriPredicate) {
this.conceptUriPredicate = conceptUriPredicate;
}

三重.java

@Entity
@IdClass(ConceptPk.class)
@Table(name = "triple")
public class TripleDBModel {

protected List<Annotation> annotations;
public Concept conceptUriSubject;
public Concept conceptUriObject;
public Concept conceptUriPredicate;



@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 = "uri_concept_subject", length = 100)
public Concept getConceptUriSubject() {
return conceptUriSubject;
}
public void setConceptUriSubject(Concept conceptUriSubject) {
this.conceptUriSubject = conceptUriSubject;
}
@Id
@Column(name = "uri_concept_object", length = 100)
public Concept getConceptUriObject() {
return conceptUriObject;
}
public void setConceptUriObject(Concept conceptUriObject) {
this.conceptUriObject = conceptUriObject;
}
@Id
@Column(name = "uri_concept_predicate", length = 100)
public Concept getConceptUriPredicate() {
return conceptUriPredicate;
}
public void setConceptUriPredicate(Concept conceptUriPredicate) {
this.conceptUriPredicate = conceptUriPredicate;
}

}

关于java - 从 Annotation 引用 Triple 的外键具有错误的列数。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5636749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com