I'm fairly new to hibernate and don't seem to fully understand the cascade.
So, I have the Job and the Client class and what I want to achieve is this:
- If I delete a client the job is deleted as well
- If I delete a job the client doesn't get deleted
My model looks something like this at the moment:
@Entity
public class Client {
@Id
@GeneratedValue
private Long clientId;
private String name;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
private List<Job> jobs;
}
@Entity
public class Job {
@Id
@GeneratedValue
private Long jobId;
private String title;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "client_id")
private Client client;
// getters, setters and some fields were omitted for brevity
}
Thank you in advance