0 Replies Latest reply on Jan 3, 2007 7:25 PM by Christopher Keith Lacno

    Need help on converting SQL to EJB QL

    Christopher Keith Lacno Newbie

      Hi all,

      Im having problems with my EJB QL statements. Im using MySQL as my database..

      The SQL statement below works perfectly on MySQL:

      select o.dateArrived, o.custName , o.IDCategory
      from tblMessages AS o WHERE o.IDCategory = "+categoryId+" and DATE_SUB( '"+dateReceived+"' , INTERVAL 2 DAY ) <= o.datArrived ORDER BY o.datArrived DESC



      When transfered the statements to my facade:
      public List getData(String categoryId, String dateReceived){
      
       return em.createQuery
       ("select o.dateArrived, o.custName , o.IDCategory"+
       "from TblMessages AS o WHERE o.IDCategory = "+categoryId+" and "+
       "and DATE_SUB( '"+dateReceived+"' , INTERVAL 2 DAY ) <= o.dateArrived,
       ORDER BY o.datReceived DESC").getResultList();
      
      }




      It produce an exception: javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: 2

      Any suggestions?

      Thanks. :)