0

我在休眠中使用级联操作时遇到了一些问题。我有一个实体(TripleDBmodel),实体的主键是使用对三个对象(概念)的引用创建的。它工作完美,我还在这些对象上添加了级联操作,我认为 TripleDBModel 实体的保存操作也将保存数据库中不存在的概念。但是它不是那样工作的。

 @Entity
 @Table(name = "triple")
 public class TripleDBModel implements java.io.Serializable{

private Concept subject;
private Concept object;
private Concept predicate;
public TripleDBModel(){

}
@Id
@ManyToOne(targetEntity=Concept.class)
@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
@JoinColumn(name="subject_uri")
public Concept getSubject() {
    return subject;
}
public void setSubject(Concept subject) {
    this.subject = subject;
}
@Id
@ManyToOne(targetEntity=Concept.class)
@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
@JoinColumn(name="object_uri")
public Concept getObject() {
    return object;
}
public void setObject(Concept object) {
    this.object = object;
}
@Id
@ManyToOne(targetEntity=Concept.class)
@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
@JoinColumn(name = "predicate_uri")
public Concept getPredicate() {
    return predicate;
}
public void setPredicate(Concept predicate) {
    this.predicate = predicate;
}

}


@Entity
@Table(name = "concept")
public class Concept implements java.io.Serializable {

private String uri;
private String label;


// private List<TripleDBModel> triple;

public Concept(String uri, String label) {
    this.uri = uri;
    this.label = label;
    this.ontologies = new ArrayList<Ontology>();
}

public Concept() {
    super();
}

@Id
@Column(name = "uri", length = 255, unique = true, nullable = false)
public String getUri() {
    return uri;
}

public void setUri(String uri) {
    this.uri = uri;
}
....

}

4

1 回答 1

0

级联选项仅适用于关系的 @OneToMany 一侧。

您应该知道何时需要创建一个新概念,因此单独坚持它应该不是问题吗?

于 2012-04-05T20:05:41.260 回答