I am curious about the arbitrary "where" clause in a Hibernate mapping file. The only information I have found on it is the following (from the Reference Guide):
"specify an arbitrary SQL WHERE condition to be used when retrieving objects of this class"
My question is: if I add a where clause to a Hibernate mapping file for class A, does that apply to associations as well? For instance, let's say I have the following classes:
Code:
public class Teacher {
private Set<Course> activeCourses;
}
Code:
public class Course {
private Teacher teacher;
private boolean active;
}
Let's say I want to restrict the set of courses for a teacher to be only the active ones. I know that I can update the course mapping file to include the necessary where clause to mandate that Courses be "active". However, will that mean that after loading a Teacher, its persistent set of Courses will also only contain active Courses?
I hope this is the case; in my real-world example, we have several classes that are in persistent sets for many others classes. It would be nice to only define that restriction in one place (e.g. the Course.hbm.xml file).
Like I said, our case is more complicated, so it would be great if this functionality exists. If not, is there some other Best Practice method of handling this?
Thanks for any help anyone can offer.