Hello,
This may seem like a very simple question, but I have been struggling with it for a while. I have two entities Client and User where Client is a parent of User. The entities are annotated as follows:
Client:
@OneToMany(mappedBy = "client", fetch = FetchType.LAZY)
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE})
private List<User> users = new ArrayList<User>();
User:
@ManyToOne(optional = false, fetch = FetchType.EAGER, cascade = {CascadeType.REFRESH})
@JoinColumn(name = "client_id")
private Client client;
public User(Client client, String userName, String password) {
client.getUsers().add(this);
}
I need deletion on the client to cascade to the user. This works if the client and user are created in one Hibernate session and the client is deleted in another Hibernate session. However, if I try to delete the client in the same session, then deleted on the user is never issued and I get org.hibernate.exception.ConstraintViolationException.
Does anybody know how to fix this?
Thanks