3 Replies Latest reply on Aug 6, 2002 2:41 PM by dsundstrom

    Date in EJB-QL problem ?

    ericmacau

      Hello,

      I am using MySQL as the CMP default datasource.

      I defined a EJB-QL as following:

      <query-method>
      <method-name>findByPeriod</method-name>
      <method-params>
      <method-param>java.util.Date</method-param>
      <method-param>java.util.Date</method-param>
      </method-params>
      </query-method>

      <ejb-ql>
      <![CDATA[
      SELECT OBJECT(a) FROM DailyCounterEJB a
      WHERE a.date BETWEEN ?1 and ?2
      ]]>
      </ejb-ql>



      But it raised exception when deployment.


      Would you please to teach me how can define EJB-QL with DATE as the parameters for confitions.

      Best regards,
      Eric



        • 1. Re: Date in EJB-QL problem ?
          dsundstrom

          EJB-QL does not allow dates for the between function. Use the &gt; and &lt; operators instead.

          • 2. Re: Date in EJB-QL problem ?
            tallyho

            Doesn't the EJB-QL specification state that you should not use Date at all? From section 11.2.11 of the specification:

            "Date and time values should use the standard Java long millisecond value. The standard way to produce
            millisecond values is to use java.util.Calendar."

            • 3. Re: Date in EJB-QL problem ?
              dsundstrom

              That section is just saying that dates should have the resolution of milliseconds, but does not say you shouldn't use dates. The date stuff in the CMP specification is very poorly written. I think this is on purpose as temporal data is a very difficult issue, and there are really not right aswers.