1 Reply Latest reply on Aug 30, 2010 3:30 PM by njrich28

    How to use the entity query framework to model the following query

    josdaniel

      We have a query which needs to check if a certain integer field points is not null and if appointmentDate is before current date? How do I write the restrictions expression for the above scenario?




      @Entity
      public class User {
      
      ...
      Integer points;
      Date appointmentDate;
      ...
      }



        • 1. Re: How to use the entity query framework to model the following query
          njrich28

          Presuming you are defining your framework query in components.xml, something like this:




               <framework:entity-query>
                    <framework:ejbql>select user from User user where user.points is not null</framework:ejbql>
                    <framework:restrictions>
                         <value>user.appointmentDate &lt; #{currentDate}</value>
                    </framework:restrictions>
               </framework:entity-query>




          The 'static' restrictions in the query (ie does not depend on something that changes like the current date) should be defined in the ejbql attribute or tag. The 'dynamic' part of the restriction should be included in the restrictions tag. Each value should have one expression language element (#{currentDate} in this case). You can have any number of value tags inside a restriction.


          currentDate is a built-in Seam component that evaluates to a new Date(). There's also currentDatetime.