2 Replies Latest reply on Jan 27, 2006 7:58 AM by fabriciobraga

    EJB QL How to find most recent date??

    fabriciobraga

      Hi all,

      I have a trouble here while trying to find most recent date register from my table.

      Here goes my finder method:


      public Project findLastCreated() throws RemoteException{
      String ejbQl = "select max(p.creationDate) from Project p";
      Project result = entityManager.createQuery(ejbQl).getSingleResult();
      return result;
      }


      When running this method it gives me an exception because something about timestamp.

      The database is MySql and the field "CREATION_DATE" is "DATETIME" type. Anyone can help me? How can I find the most recent date register using EJB QL?

      Regards,
      Fabricio Braga

        • 1. Re: EJB QL How to find most recent date??
          maximwirt

           

          "fabriciobraga" wrote:
          Hi all,

          I have a trouble here while trying to find most recent date register from my table.

          Here goes my finder method:


          public Project findLastCreated() throws RemoteException{
          String ejbQl = "select max(p.creationDate) from Project p";
          Project result = entityManager.createQuery(ejbQl).getSingleResult();
          return result;
          }


          When running this method it gives me an exception because something about timestamp.

          The database is MySql and the field "CREATION_DATE" is "DATETIME" type. Anyone can help me? How can I find the most recent date register using EJB QL?

          Regards,
          Fabricio Braga


          replace
          Project result = entityManager.createQuery(ejbQl).getSingleResult();

          witn
          Date date = (Date)entityManager.createQuery(ejbQl).getSingleResult();


          • 2. Re: EJB QL How to find most recent date??
            fabriciobraga


            maximwirt,

            I've follow your suggestion and now it works fine. Thanks a lot.

            Regards,
            Fabricio Braga