5 Replies Latest reply on Nov 14, 2008 2:49 AM by itsme

    Weired Query Synthax exception???

    rahb

      I am using following JPQL Constructor Expressions...

      select new com.cList.CListing() from CSummaryByDateWeek cdtwk where cdtwk.pk.Id = 1


      I am now specifying full path of the constructor but still getting exception as follows

      I am getting weired exception

      19:47:17,265 ERROR [PARSER] line 1:70: unexpected token: )
      19:47:17,312 ERROR [PARSER] line 1:72: expecting CLOSE, found 'FROM'

        • 1. Re: Weired Query Synthax exception???
          jaikiran

           

          "rahb" wrote:


          select new com.cList.CListing() from CSummaryByDateWeek cdtwk where cdtwk.pk.Id = 1



          Try this

          select cdtwk from CSummaryByDateWeek cdtwk where cdtwk.pk.Id = 1



          • 2. Re: Weired Query Synthax exception???
            itsme

            in addition to jaikiran if you need a subset of attributes of an persistent entity you can use an non persistent class by giving the full qualified class name and lsit all parameters for that constructor (see spec page 100 for more details).
            The spec says


            A constructor may be used in the SELECT list to return one or more Java instances. The specified class
            is not required to be an entity or to be mapped to the database. The constructor name must be fully qualified.
            SELECT Clause Enterprise JavaBeans 3.0, Final Release Query Language
            101 5/2/06
            Sun Microsystems, Inc.
            If an entity class name is specified in the SELECT NEW clause, the resulting entity instances are in the
            new state.
            SELECT NEW com.acme.example.CustomerDetails(c.id, c.status, o.count)
            FROM Customer c JOIN c.orders o
            WHERE o.count > 100


            • 3. Re: Weired Query Synthax exception???
              rahb


              Thansk for the quick reply............

              I am getting next problem as


              I using this query

              select new com.CReport(cdtwk.cStartDate) " +
              " from CByDateWeek cdtwk where cdtwk.pk.cId

              but it's not finding constructor in class CReport class...

              Data type cStartDate in CByDateWeek is Date

              I have constructor in CReport class as

              public CReport(Date sdate){
              ...
              }

              public CReport(Time sdate){
              ...
              }

              public CReport(TimeStamp sdate){
              ...
              }

              but nothing is working ..it says
              Constructor not found exception.......what to more try???

              02:16:41,265 ERROR [PARSER] Unable to locate appropriate constructor on class [com.CReport]
              [cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.CReport]

              In more detail

              Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class com.CReport.

              Thanks in advance.

              • 4. Re: Weired Query Synthax exception???
                itsme

                I haven't used this with complex types like dates or timestamps. How is the date/timestamp written to the database? For dates I always use the long value and for timestamps the string representation.

                • 5. Re: Weired Query Synthax exception???
                  itsme

                  As by reading the spec, especially the section 4.14 BNF (BNF for the Java Persistence query language) it states:


                  ...
                  single_valued_path_expression ::=
                  state_field_path_expression | single_valued_association_path_expression
                  state_field_path_expression ::=
                  {identification_variable | single_valued_association_path_expression}.state_field
                  single_valued_association_path_expression ::=
                  identification_variable.{single_valued_association_field.}* single_valued_association_field
                  ...
                  constructor_expression ::=
                  NEW constructor_name ( constructor_item {, constructor_item}* )
                  constructor_item ::= single_valued_path_expression | aggregate_expression
                  aggregate_expression ::=
                  { AVG | MAX | MIN | SUM } ([DISTINCT] state_field_path_expression) |
                  COUNT ([DISTINCT] identification_variable | state_field_path_expression |
                  single_valued_association_path_expression)
                  ...

                  As per this I'm not sure whether complex types likes dates and timestamps are supported to be used in constructor expressions.