In Bean class there is this annotation:
class User {
@OneToMany(targetEntity = Feedback.class,mappedBy = "user",cascade =
CascadeType.ALL,fetch = FetchType.LAZY)
private List<Feedback> feedbacks;
...
}
I want to delete user, which has some feedbacks. If I type this:
sessionFactory.getCurrentSession().delete(
sessionFactory.getCurrentSession().get(User.class, id));
user will be deleted successfully, (id is primary key). But I want to delete all users, witch, have role="admin", and if i type this query:
String query = "DELETE from User WHERE role='" + role + "'";
sessionFactory.getCurrentSession().createQuery(query).executeUpdate();
It will be delete only users without references to feedbacks. What wrong with my query? Please help.