-->
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.  [ 2 posts ] 
Author Message
 Post subject: HQL Query?
PostPosted: Mon Nov 22, 2004 12:41 am 
Beginner
Beginner

Joined: Thu Sep 23, 2004 6:03 am
Posts: 27
Hibernate version:2.1.1

Mapping documents:Xdoclet

Name and version of the database you are using:MySQL 4

I am trying to write a query which returns a list depending on the critieria I have entered. This query needs to be build dynamical depending on the number of arguments supplied. Can anyone help me how I should be constructing the query string.

Code:
public List getRightsForLicence(Licence licence, List rightsTypes) {

Object[] objects = new Object[2];

for(int i = 0; i<rightsTypes.size(); i++) {
         
         RightsType rightsType = (RightsType)rightsTypes.get(i);
         
         objects[0] = licence;
         objects[1] = rightsType;
      
         rights.addAll( getHibernateTemplate().find("from Rights r where r.licence=? and r.rightsType=?", objects) );      
      }

return rights;
}


I would just like to return a list of all the results as opposed to a list of results that contains separate lists of results.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 1:06 am 
Beginner
Beginner

Joined: Thu Sep 23, 2004 6:03 am
Posts: 27
Sorry I copied a older version of the code, I'm actually returning a map:

Code:
   public Map getRightsForLicence(Licence licence, List rightsTypes) {
      
      Map rightsMap       = new HashMap();      
      List returnedRights   = new LinkedList();
      List rights       = new LinkedList();
      
      
      Object[] objects = new Object[2];
      
      for(int i = 0; i<rightsTypes.size(); i++) {
         
         RightsType rightsType = (RightsType)rightsTypes.get(i);
         
         objects[0] = licence;
         objects[1] = rightsType;
      
         rights = getHibernateTemplate().find("from Rights r where r.licence=? and r.rightsType=?", objects);         
         
         if(!rights.isEmpty()) {
             for (Iterator iter = rights.iterator(); iter.hasNext();) {
                Rights element = (Rights) iter.next();
                rightsMap.put(element.getId(), element);
             }          
          }      
      }      
      
      return rightsMap;
   }


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

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.