Joined: Fri May 21, 2004 5:30 pm Posts: 3
|
Hi guys,
I have two classes and there is many-to-one relationship from class A to B. There isn't any relationship from B to A. The A class has getB method which return the B class. I would like to make that delete the B class should delete all A classes which refer to that B (session.delete(instanceOfClassB) ==> delete the instanceOfClassB AND delete all A classes which refer to that instanceOfClassB).
/** @hibernate.class table="A" */
public class A {
private int id = -1;
private String nazwa;
private B b;
/** @hibernate.id generator-class="native" column="a_id" unsaved-value="-1"
* @hibernate.generator-param name="sequence" value="A_sequence" */
public int getId() {
return id;
}
/** @hibernate.property */
public String getNazwa() {
return nazwa;
}
/**@hibernate.many-to-one column="fk_b_id" cascade="all" */
public B getB() {
return b;
}
public void setB(B b) {
this.b = b;
}
public void setNazwa(String nazwa) {
this.nazwa = nazwa;
}
public void setId(int id) {
this.id = id;
}
}
/**@hibernate.class table="B" */
public class B{
private int id = -1;
private String nazwa;
/**
* @hibernate.id generator-class="native" column="b_id" unsaved-value="-1"
* @hibernate.generator-param name="sequence" value="B_sequence"*/
public int getId() {
return id;
}
/** @hibernate.property */
public String getNazwa() {
return nazwa;
}
public void setNazwa(String nazwa) {
this.nazwa = nazwa;
}
public void setId(int id) {
this.id = id;
}
}
|
|