-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Conditional loading of objects
PostPosted: Tue Jun 03, 2008 10:25 am 
Newbie

Joined: Tue Jun 03, 2008 9:12 am
Posts: 2
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 :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.