littypreethkr wrote:
Consider the entities Subject, Course and Teacher.
Java is a subject
Beginners Java is a Course related to Java.
Advanced Java is a Course related to Java.
Teacher Sam teaches both.
So Subject to Course and Teacher to Course are one to many relations.
But Course exists even if there are no assigned teacher to it. May be a new course just introduced by the institute for which they are looking for a faculty.
But a Course does not exists without a Subject. If the institute decides that they will no longer teach Java then all the courses related to java also stops to exist.
So in Subject to Course relation Course is owned by Subject
But in Teacher to Course relation Course is not owned by teacher
Hope this clarifies the things.
Thanks. I understand what you mean now.
And solved my problem:
@SuppressWarnings("unchecked")
public void removeRoleById(Long roleId) {
Role role = this.get(roleId);
List<User> users = this.getHibernateTemplate().find("select u from User u join u.roles r where r.id = ?", roleId);
for(User user : users){
user.removeRole(role);
this.getHibernateTemplate().saveOrUpdate(user);
}
this.getHibernateTemplate().delete(role);
}
BTW, do you know what's the difference between save() and saveOrUpdate(), can't we just use saveOrUpdate() all the time?
Thanks.