Could you please tell me how you I might structure the following table/classes to avoid circular references? I have the following defined in a "Bachelor" degree class:
@Entity
public class Bachelor {
...
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "fk_bachelor")
private Study study;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "fk_prior")
private List<Study> priorStudies;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "fk_exchange")
private List<Study> exchangeStudies;
...
}
@Entity
class Study {
private String title;
private String placeOfStudy;
etc
...
}
This is to represent a bachelor degree which has one Study record for details of the bachelor degree. If the applicant specifies they've completed a bachelor degree they can then specify one or more prior and exchange studies. An example of a bachelor degree plus one prior degree results is the following:
bachelor id | fk_bachelor 10003 | 10000
study id | title | fk_prior 10000 | Bachelor of Arts | 10001 | Prior Degree | 10003
This seems to work fine except if I need to delete items from the tables. I also received a warning about having circular references from the compiler. So I can't first delete from Bachelor because Study references it by fk_prior, and I can't first delete from Study because Bachelor references it. I'm guessing this isn't good practice to structure it like this.