2 Replies Latest reply on Apr 21, 2003 10:19 AM by raja05

    Help with EJB-QL needed!!! Wrong generated sql statement

    smilie


      Hi!

      I have the following problem. My ejb-jar.xml:


      <query-method>
      <method-name>findByName</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <ejb-ql><![CDATA[SELECT OBJECT(a) FROM StatusEntity AS a WHERE a.name= ?1]]></ejb-ql>


      and in my SessionEan I call the finder method like this:
      StatusEntityLocal local = home.findByName(statusValue.getName());

      I am using XDoclet to generate the ejb classes. When I execute the code, I ve got an db error that the sql statement was not finished. After I looked in the log, I saw that SQL generated by JBoss is like this:

      SELECT NAME FROM STATUS bla WHERE bla.NAME = ?

      So JBoss replaced the variable only with a ? ... What could I do?


      Regards,

      Thilko

        • 1. Re: Help with EJB-QL needed!!! Wrong generated sql statement
          pdelgado0

          To be honest I'm not sure where is the problem but try the following:
          Perhaps the characters ' before and after the ?1 are missing, it'd be like this ...

          <ejb-ql>
          [CDATA[SELECT OBJECT(a) FROM StatusEntity AS a WHERE a.name= '?1']]
          </ejb-ql>

          In SQL you can't compare with a String without those '

          If it still doesn't work try redefining the query in jboss-ql. I know it's not the best solution but if it works you can go on working and don't wasting more time in this silly problems.

          Good luck and you'll tell me if it works! I hope so!

          Pablo

          • 2. Re: Help with EJB-QL needed!!! Wrong generated sql statement
            raja05

            The single ? should be correct because whatever you entered is converted to a Preparedstatement, so all the "IN" variables and "OUT" variables will be converted to ?. There is something else thats causing the issue. Can you post the stack tracE?

            -Raj