2 Replies Latest reply on Aug 29, 2003 4:29 PM by thegiantsquid

    EJB QL (JBossQL?) and Dates....

    thegiantsquid Newbie

      It's pretty well established that the current version of EJB-QL cannot do much outside of dealing with primitive types (and, it can't sort on Date at all).


      I've read that JBossQL can do this... any pointers to documentation?

      What I'm looking for is a strategy to solve the following problem:

      I have a WeatherReading Entity bean, with a persistent field IssuanceTime (of type java.util.Date). I have several thousand of these entries, and I'd like to have a function (in EJBQL/JBossQL) that retrieves the latest weather reading issued prior to a Date parameter. (I'm currently storing this in PostgreSQL using the timestamp datatype).

      Something like:
      findLatestWeatherReadingBefore(Date pDate)

      What are my options here? Do I have to convert everything to milliseconds and back?

        • 1. Re: EJB QL (JBossQL?) and Dates....
          Adrian Brock Master

          You'll find the CMP2.0 docs on the "Documentation link"

          JBossQL lets you use Order By, the type mapping can
          be configured. If the global config is incorrect, just change it
          for that field.

          Regards,
          Adrian

          • 2. Re: EJB QL (JBossQL?) and Dates....
            thegiantsquid Newbie

            Would this be the appropriate xdoclet code then:

            * @ejb:finder signature="ConsolidatedMetReadingBean findLatestInBin(java.util.Date binDate)"
            *
            * @jboss:finder-query
            * name="findLatestInBin"
            * query="SELECT DISTINCT OBJECT(c) FROM ConsolidatedMetReadingBean AS c WHERE c.BinID = binDate LIMIT 1 ORDER BY IssuanceTime"

            Here, IssuanceTime actually describes the record, and BinID is a Date signifying the start-time of a 15 minute interval (say 10:15 or 12:30) for which that record belongs. (So, all records released between 10:15:00:00 and 10:29:59:99 would belong to the 10:15 "Bin")

            The query would retrieve the latest ConsolidatedMetReading (based on IssuanceTime) from all ConsolidatedMetReadings with that same BinID.