0 Replies Latest reply on Dec 12, 2009 10:31 PM by Sven Kilchenmann

    CreatQuery with date

    Sven Kilchenmann Newbie

      I have an event class


      ...@NotNull
           private Date startDate = new Date();..



      now i create a query which will select all events within a date range.




      startCal = new GregorianCalendar();
               startCal.setTime(new Date());
                startCal.add(GregorianCalendar.DAY_OF_MONTH, 15);
                startCal.add(GregorianCalendar.AM_PM, GregorianCalendar.AM);
                startCal.set(GregorianCalendar.HOUR,24);
                startCal.set(GregorianCalendar.MINUTE,0);
                endCal = new GregorianCalendar();
                endCal.setTime(new Date());
                endCal.add(GregorianCalendar.DAY_OF_MONTH, 15);
                endCal.add(GregorianCalendar.AM_PM, GregorianCalendar.PM);
                endCal.set(GregorianCalendar.HOUR,0);
                endCal.set(GregorianCalendar.MINUTE,0);
               List<Event> events = (List<Event>) this.entityManager.createQuery("SELECT e FROM Event e WHERE e.startDate > :startDate AND e.startDate < :endDate")
               .setParameter("startDate", startCal.getTime())
               .setParameter("endDate", endCal.getTime())
               .getResultList();
               log.info("Found {0} events - {1} bis {2}",events.size(), startCal.getTime(), endCal.getTime());



      but if the date from database matches i don't have any entries within events.
      Anyone could help!
      Thanks a lot