-->
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: Query by Example - object as property of example object
PostPosted: Fri Jul 18, 2008 7:54 am 
Newbie

Joined: Fri Jul 18, 2008 7:41 am
Posts: 1
Hi Girls and Boys,

I wasn't able to find what I needed in Documentation (nor could Google), so I decided to post here. I am trying to build a search for a small j2ee application, and I decided to give Query by Example feature a chance. In the documentation is described that you can set a property of an Example object, but is not considered that that property could also be an object, so here is what I tried:
Code:
AnomalyReport report1 = new AnomalyReport();
      
      Category cat1 = new Category();
      cat1.setId(2);
      cat1.setValue("cat 2");
      report1.setCategory(cat1);
      
   

      List<AnomalyReport> result = null;
      try {
         Example exampleReport = Example.create(report1)
                                 .ignoreCase()
                                 .enableLike();
                                 
         
         Session session = (Session) entityManager.getDelegate();
         Criteria criteria = session.createCriteria(AnomalyReport.class)
                              .add(exampleReport);
         criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
         result = (List<AnomalyReport>) criteria.list();AnomalyReport>) criteria.list();
...


Apparently this query returns all the entries, so it is not getting just reports with category id '2' and category value cat 2".

Am I doing something wrong? Or I just missed the whole point :)


Thanks,
Nebojsa


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.