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: QBE not working
PostPosted: Tue May 19, 2009 1:50 pm 
Beginner
Beginner

Joined: Wed Nov 12, 2008 12:07 pm
Posts: 21
I'm trying to use query by example combining two classes, just like the second example given in page 682 of "Java Persistence with Hibernate".
I have a class Route that has a List of Waypoint, called waypointList. I want to find all routes that has a waypoint with name "WP2":
Code:
      Waypoint wp = new Waypoint();
      wp.setName("WP2");
      Route r = new Route();
      
      Example routeExample = Example.create(r).excludeZeroes();
      Example waypointExample = Example.create(wp).excludeZeroes();
      
      DetachedCriteria c;
      
      // --------------------------------------------------------------------//
      
      c = DetachedCriteria.forClass(Route.class)
      .add(routeExample)
      .createCriteria("waypointList")
      .add(waypointExample);

      List result = routeDAO.findByCriteria(c);
      if (result.size() == 0) System.out.println(" EMPTY LIST! 1");
      else {         
         for(Object o : result){
            System.out.println("Route: " + ((Route) o).getOid());
         }
         System.out.println("size = " + result.size());         
      }      

      
      System.out.println("--------------------------------------------------------------------");
      
      c = DetachedCriteria.forClass(Route.class)
      .add(routeExample);
      
      List result2 = routeDAO.findByCriteria(c);
      if (result2.size() == 0) System.out.println(" EMPTY LIST! 2");
      else {         
         for(Object o : result2){
            System.out.println("Route: " + ((Route) o).getOid());
         }
         System.out.println("size = " + result2.size());         
      }
      
      
      System.out.println("--------------------------------------------------------------------");

      c = DetachedCriteria.forClass(Waypoint.class);
      c.add(waypointExample);


      List<Waypoint> result3 = waypointDAO.findByCriteria(c);
      if (result2.size() == 0) System.out.println(" EMPTY LIST! 3");
      else {         
         for(Object o : result3){
            System.out.println("WPoint: " + ((Waypoint) o).getOid());
         }
         System.out.println("size = " + result2.size());         
      }


The result is:

Code:
EMPTY LIST! 1
--------------------------------------------------------------------
Route: 70
Route: 71
Route: 72
size = 3
--------------------------------------------------------------------
WPoint: 81
WPoint: 83
WPoint: 85
size = 3


That is, it finds the waypoints with that name, it finds all routes but it doesn't find the two together.

How can I perform this search with QBE?
Thank you


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.