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;
}
....
}
什麼是「不工作」。你期望什麼?它是做什麼的?你正在執行的代碼是什麼? – 2012-04-05 09:53:11
感謝您的回答。如果出現在tripleDBmodel中的概念尚未保存(不在數據庫中),我使用session.save(tripleDBmodel),我期望這個概念將被保存,然後它會出現在表概念中,我期望行爲有一個級聯操作。 – silvestrelosada 2012-04-05 10:54:11