Hi,
I'm a beginner with using Hibernate and I've got a question. I have a database in which records are never deleted, instead when you remove a client in the application, the client's status is set to inactive, the same for most other objects. A client has a list of members, which I define with a one-to-many relationship. When I select a client in the application, I want to load the members of that client, which works fine. However, I only want to load the members which are active, so where active = true.
I could of course just write this method for fetching members of a specific client where the member is active:
Code:
public static ArrayList<Member> getAllMembers(Client c)
{
Query q = HibernateUtil.createQuery("from Member m where m.client = :c and m.active = true");
q.setParameter("c", c);
ArrayList<Member> list = (ArrayList<Member>) q.list();
return list;
}
However, that partially defeats the purpose of Hibernate because I would rather just say 'ArrayList<Member> = c.getMembers();' and that it only loads the members which are active.
So my question basically is: is it possible to specify any conditions for loading of objects without resorting to hsql and extra DAO methods? It's no big problem, but if it's possible then I wanna do it right from the start rather than find out later that I've been doing redundant work.
I use annotations for my mapping.
I hope the problem is clear and I would appreciate any help :)