-->
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: ID property not included in Criteria
PostPosted: Wed Jun 03, 2009 6:40 pm 
Newbie

Joined: Fri Nov 11, 2005 4:42 am
Posts: 17
Hi Everybody,
I have some code that takes a domain model creates a Criteria then adds an Example created with the model. Then it looks for any properties in the model that are domain objects and adds subCriteria to the criteria. It does this recursively. Everything works fine except that the id property is not included...

CODE:

Code:
   @SuppressWarnings("unchecked")
   public List<T> search(T example) {
      if (log.isDebugEnabled())
         log.debug("entering 'search' method...");
   
      Criteria crit = getSession().createCriteria(persistentClass); 
      return loadCriteria(crit,example).list();
   }

   private Criteria loadCriteria(Criteria crit, BaseAuditable example){

      // create and add an Example
      crit.add(Example.create(example).excludeZeroes().ignoreCase().enableLike(MatchMode.ANYWHERE));
      
      // iterate over the BaseAuditable properties
      // create Criteria for each none null BaseAuditable
      // call this recursively
      try
      {
         PropertyDescriptor [] descriptors = PropertyUtils.getPropertyDescriptors(example);
         for (PropertyDescriptor descriptor: descriptors)
         {
            if (BaseAuditable .class.isAssignableFrom(descriptor.getPropertyType()))
            {
               Method getter = descriptor.getReadMethod();
               BaseAuditable property =(BaseAuditable)getter.invoke(example, (Object[])null);
               if (property != null)
               {
                  log.debug("adding " + descriptor.getName() + " to Critieria.");
                  loadCriteria(crit.createCriteria(descriptor.getName()), property);
               }
            }
         }
      }
      catch (Exception e)
      {
         throw new IllegalStateException(e);
      }
      log.debug(crit);
      return crit;
   }

THE CALL:
Code:
Issue example = new Issue();
// set filtering criteria
example.setVisit(new Visit());
example.getVisit().setId(visit.getId());
example.getVisit().setNumMedicalDoctorAttendees(100);

// get filtered issues
List issues = walkRoundsIssueManager.search(example);


LOG:
Quote:
DEBUG [btpool0-1] GenericDaoHibernate.search(152) | entering 'search' method...
DEBUG [btpool0-1] GenericDaoHibernate.loadCriteria(162) | CriteriaImpl(com.pascalmetrics.model.products.walkrounds.Issue:this[][example (com.pascalmetrics.model.products.walkrounds.Issue@6ee035[created=<null>,updated=<null>,id=<null>,updatingUserId=<null>,comments=<null>,description=<null>,proposedAction=<null>,version=<null>,status=<null>,hidden=false,issueCategory=<null>,subCategory=<null>])])
DEBUG [btpool0-1] GenericDaoHibernate.loadCriteria(190) | adding visit to Critieria.
DEBUG [btpool0-1] GenericDaoHibernate.loadCriteria(162) | Subcriteria(visit:)
DEBUG [btpool0-1] GenericDaoHibernate.loadCriteria(200) | Subcriteria(visit:)
DEBUG [btpool0-1] GenericDaoHibernate.loadCriteria(200) | CriteriaImpl(com.pascalmetrics.model.products.walkrounds.Issue:this[Subcriteria(visit:)][example (com.pascalmetrics.model.products.walkrounds.Issue@6ee035[created=<null>,updated=<null>,id=<null>,updatingUserId=<null>,comments=<null>,description=<null>,proposedAction=<null>,version=<null>,status=<null>,hidden=false,issueCategory=<null>,subCategory=<null>]), example (com.pascalmetrics.model.products.walkrounds.Visit@196a6ac[created=<null>,u
pdated=<null>,id=1,dateOfVisit=<null>,assignment=<null>,numRegisteredNurseAttendees=<null>,updatingUserId=<null>,description=<null>,version=<null>,issues=[],hidden=false,numMedicalDoctorAttendees=100,numOtherAttendees=<null>])])
DEBUG [btpool0-1] SQL.log(401) | select this_.id as id20_2_, this_.created as created20_2_, this_.updated as updated20_2_, this_.updating_user_id as updating4_20_2_, this_.version as version20_2_, this_.hidden as hidden20_2_, this_.category as category20_2_, this_.comments as comments20_2_, this_.description as descript9_20_2_, this_.proposedAction as propose10_20_2_, this_.status as status20_2_, this_.subCategory as subCate12_20_2_, this_.visit_id as visit13_20_2_, visit1_.id as id21_0_, visit1
_.created as created21_0_, visit1_.updated as updated21_0_, visit1_.updating_user_id as updating4_21_0_, visit1_.version as version21_0_, visit1_.hidden as hidden21_0_, visit1_.assignment_id as assignment13_21_0_, visit1_.dateOfVisit as dateOfVi7_21_0_, visit1_.description as descript8_21_0_, visit1_.numMedicalDoctorAttendees as numMedic9_21_0_, visit1_.numOtherAttendees as numOthe10_21_0_, visit1_.numRegisteredNurseAttendees as numRegi11_21_0_, visit1_.visitInterval as visitIn12_21_0_, assignme
nt4_.id as id19_1_, assignment4_.created as created19_1_, assignment4_.updated as updated19_1_, assignment4_.updating_user_id as updating4_19_1_, assignment4_.version as version19_1_, assignment4_.hidden as hidden19_1_, assignment4_.wr_clinical_area_id as wr9_19_1_, assignment4_.executive_id as executive8_19_1_, assignment4_.scheduledVisit as schedule7_19_1_ from wr_issues this_ inner join wr_visit visit1_ on this_.visit_id=visit1_.id left outer join wr_assignment assignment4_ on visit1_.assignm
ent_id=assignment4_.id where (this_.hidden=?) and (visit1_.hidden=? and visit1_.numMedicalDoctorAttendees=?)


Sorry about all the aliases -
THIS IS THE QUESTION:
where (this_.hidden=?) and (visit1_.hidden=? and visit1_.numMedicalDoctorAttendees=?)

why doesn't visit1_id=? appear in this sql????

Thanks


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.