Hello, although I made a little research on this, and I found a lot of threats opened in Internet, I couldn't solve my problem. I atache my code:
Triple.java the primary key is made by 3 uris from three different concepts, but it is the same column (is it a problem?)
Code:
@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 Code:
@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;
}
Annotation.java Code:
@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;
}
But I am getting this error:
Caused by: org.hibernate.AnnotationException: A Foreign key refering TripleDBModel from Annotation has the wrong number of column. should be 3
What am I doing wrong?? Thanks in advance