-->
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: Criteria and collections of elements
PostPosted: Wed Dec 21, 2005 5:20 am 
Newbie

Joined: Wed Dec 21, 2005 4:41 am
Posts: 2
Location: Belgium
I have a class ContractRequest that contains a map of <String, String>, mapped like so:
Code:
   /**
    * @hibernate.map table="icd.tblcontractrequestfield"
    * @hibernate.collection-key   column="cnrq_id"
    * @hibernate.collection-element column="cnrf_value" type="string"
    * @hibernate.collection-index column="cnrf_key" type="string"
    * @return
    */
   public Map getFieldMap() {
      if(fieldMap==null) fieldMap = new HashMap();
      return fieldMap;
   }
   public void setFieldMap(Map fieldMap) {
      this.fieldMap = fieldMap;
   }

Now I'm trying to query ContractRequest by searching the items in that map, but I can't find a way to do it using Criteria. This is how I'm doing it with HQL:
Code:
public List findAllByFilter(Long reqId, int status, Calendar requested, String field) throws BusinessException {
      String query = "select distinct cr from ContractRequest cr left outer join cr.fieldMap as field where cr.id = cr.id";
      List params = new ArrayList();
      List paramTypes = new ArrayList();
      if(reqId!=null) {
         query += " and cr.id = ?";
         params.add(reqId);
         paramTypes.add(Hibernate.INTEGER);
      }
      if(StringUtils.isNotEmpty(field)) {
         query += " and upper(field) like ?";
         params.add("%"+(field.toUpperCase())+"%");
         paramTypes.add(Hibernate.STRING);
      }
      System.err.println(query);
      Query hnquery = new HibernateFilter().getDatabaseContext().getSession().createQuery(query);
      hnquery.setParameters(params.toArray(), (Type[]) paramTypes.toArray(new Type[0]));
      return hnquery.list();
      
   }

But that just seems plain wrong to me, and the query is to become a lot more complex in the future so I would like to do this using Criteria. I just can't find how to do this using Criteria. Since the collection is not an assocation, I can't use createCriteria("fieldMap") and even if I could do that I wouldn't know where to go from there.
Any help would be greatly appreciated.


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.