4 Replies Latest reply on Nov 18, 2005 8:59 AM by dornus

    EntityManager returns wrong number of results

      I have the following query.
      When I run it, it returns 1 row.

      When I copy and paste the IDENTICAL query into MySql it returns 2 rows.

      What is going on???

      public void test(String ids, int userId){
       System.out.println(
       "select * from My_Table o " +
       " where o.userId = "+userId+
       " and o.id in ( "+ids+" ) "
       );
      
       final Query q = em.createNativeQuery(
       "select * from My_Table o " +
       "where o.userId = :userId "+
       "and o.id in ( :ids ) ", My_Table.class
       );
       q.setParameter("ids", ids);
       q.setParameter("userId", userId);
      
       List<My_Table> results = q.getResultList();
       System.out.println("Size: "+results.size());
      }
      
      Running the method above I get
      
       INFO [STDOUT] select * from My_Table o where o.userId = 4 and o.id in ( 5,2 )
       INFO [STDOUT] Size: 1
      
      
      
      Copy and pasting that query directly into MySql results in 2 rows