I have a class A and classes B and C:
public class A {
@Id
protected String name;
...
}
public class B {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@NotNull
@ManyToOne
private A a;
....
}
public class C {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@NotNull
@ManyToOne
private A a;
....
}
If A entity is removed, I want all child entities to be removed too. I dont want a bidirectional relationship (in order to no have cycles between the classes and in order to not add more attributes to class A). Is that possible using Hibernate or have I to do this programatically in my service class?.
I guess if bidirectional relationship is needed for this I can write a parent class for B and C and use this parent class in a list to reference the childs in class A?