5 Replies Latest reply on Mar 7, 2003 3:46 PM by aragorn94

    error in your SQL syntax near 'FROM product WHERE ' at line

    wqhhust

      I use eclipse+lomboz,When I deploy the created by jar file to jboss,there is no error,but when I run the Test class, jboss throws an exception:

      javax.ejb.FinderException: Find failed: java.sql.SQLException: Syntax error or access violation: You have an error in your SQL syntax near 'FROM product WHERE ' at line 1

      But I didnot define the findByPrimaryKey() method and it is created by jboss, and the exception is really throws by that method,does some created error by xdoclet?I use xdoclet 1.1.2



      package hust;

      import javax.ejb.EntityBean;

      /**
      * @ejb:bean name="Product"
      * jndi-name="jndi/ProductBean"
      * type="CMP"
      * cmp-version="2.x"
      * @jboss:table-name table-name="product"
      * @ejb:pk
      * class="java.lang.Integer"
      * generate="false"
      **/
      public abstract class ProductBean implements EntityBean {

      /**
      * @ejb:interface-method
      * tview-type="remote"
      * @ejb:persistent-field
      **/
      public abstract String getName();
      public abstract void setName(String pname);
      /**
      * @ejb:interface-method
      * tview-type="remote"
      *@ejb:persistent-field
      *@ejb:pk-field
      **/
      public abstract int getId();
      public abstract void setId();
      }


      and the test class is :public class Test {

      private hust.ProductHome getHome() throws NamingException {
      return (hust.ProductHome) getContext().lookup(
      hust.ProductHome.JNDI_NAME);
      }
      private InitialContext getContext() throws NamingException {
      Hashtable props = new Hashtable();

      props.put(
      InitialContext.INITIAL_CONTEXT_FACTORY,
      "org.jnp.interfaces.NamingContextFactory");
      props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
      InitialContext initialContext = new InitialContext(props);
      return initialContext;
      }
      public void testBean() {

      try {
      hust.Product myBean = getHome().findByPrimaryKey(new Integer(1));
      System.out.println(myBean.getName());
      } catch (RemoteException e) {
      e.printStackTrace();
      } catch (NamingException e) {
      e.printStackTrace();
      }
      catch(Exception e){
      e.printStackTrace();
      }
      }

      public static void main(String[] args) {
      Test test = new Test();
      test.testBean();

      }
      }




        • 1. Re: error in your SQL syntax near 'FROM product WHERE ' at l
          aragorn94

          Three changes in your XDolclets tags (options i use with Eclipse & Lomboz):

          - Replace (should not be the problem)
          * generate="false" => * generate="true"



          - add this tag before your setter methods (are they really generated ?)

          * @ejb:interface-method

          - Replace the tag in getId method
          *@ejb:pk-field

          by
          * primkey-field = "id"
          in * @ejb:bean tag

          I read somewhere it's better and i use second (but i don't think this has many impact)



          Please reply if all is OK. (I will check with my code this afternoon)


          • 2. Re: error in your SQL syntax near 'FROM product WHERE ' at l
            aragorn94

            Correction :
            i don't use generate attribute in @ejb:pjk tag (but true is the default)

            but i use
            primkey-field = "id" generate = "true"
            in the @ejb:bean tag

            here's a complete XDoclet tags i use for a bean (no *@ejb:pk-field at method level) :

            /**
            *
            *
            * @ejb:bean name="User"
            * jndi-name="jndi/UserBean"
            * primkey-field = "email" generate = "true" schema = "UserBeanSch" view-type = "local"
            * type="CMP"
            * cmp-version="2.x"
            *
            * @ejb:pk class = "java.lang.String"
            *
            * @ejb:finder
            * signature="Collection findAll()"
            * query="select Object(o) from UserBeanSch as o"
            * result-type-mapping="Local"
            *
            * @jboss:table-name table-name = "user"
            *
            * @jboss:create-table "true"
            *
            **/

            • 3. Re: error in your SQL syntax near 'FROM product WHERE ' at l
              aragorn94

              Correction :
              i don't use generate attribute in @ejb:pjk tag (but true is the default)

              but i use (i think i had some problem like yours before settings this XDoclet attributes, not sure) :

              primkey-field = "id" generate = "true"
              in the @ejb:bean tag

              here's a complete XDoclet tags i use for a bean (no *@ejb:pk-field at method level) :

              /**
              *
              *
              * @ejb:bean name="User"
              * jndi-name="jndi/UserBean"
              * primkey-field = "email" generate = "true" schema = "UserBeanSch" view-type = "local"
              * type="CMP"
              * cmp-version="2.x"
              *
              * @ejb:pk class = "java.lang.String"
              *
              * @ejb:finder
              * signature="Collection findAll()"
              * query="select Object(o) from UserBeanSch as o"
              * result-type-mapping="Local"
              *
              * @jboss:table-name table-name = "user"
              *
              * @jboss:create-table "true"
              *
              **/

              • 4. Re: error in your SQL syntax near 'FROM product WHERE ' at l
                aragorn94

                Correction :
                i don't use generate attribute in @ejb:pjk tag (but true is the default)

                but i use (i think i had some problem like yours before settings this XDoclet attributes, not sure) :

                primkey-field = "id" generate = "true"
                in the @ejb:bean tag

                here's a complete XDoclet tags i use for a bean (no *@ejb:pk-field at method level) :

                /**
                *
                *
                * @ejb:bean name="User"
                * jndi-name="jndi/UserBean"
                * primkey-field = "email" generate = "true" schema = "UserBeanSch" view-type = "local"
                * type="CMP"
                * cmp-version="2.x"
                *
                * @ejb:pk class = "java.lang.String"
                *
                * @ejb:finder
                * signature="Collection findAll()"
                * query="select Object(o) from UserBeanSch as o"
                * result-type-mapping="Local"
                *
                * @jboss:table-name table-name = "user"
                *
                * @jboss:create-table "true"
                *
                **/

                • 5. Re: error in your SQL syntax near 'FROM product WHERE ' at l
                  aragorn94

                  Correction :
                  i don't use generate attribute in @ejb:pjk tag (but true is the default)

                  but i use (i think i had some problem like yours before settings this XDoclet attributes, not sure) :

                  primkey-field = "id" generate = "true"
                  in the @ejb:bean tag

                  here's a complete XDoclet tags i use for a bean (no *@ejb:pk-field at method level) :

                  /**
                  *
                  *
                  * @ejb:bean name="User"
                  * jndi-name="jndi/UserBean"
                  * primkey-field = "email" generate = "true" schema = "UserBeanSch" view-type = "local"
                  * type="CMP"
                  * cmp-version="2.x"
                  *
                  * @ejb:pk class = "java.lang.String"
                  *
                  * @ejb:finder
                  * signature="Collection findAll()"
                  * query="select Object(o) from UserBeanSch as o"
                  * result-type-mapping="Local"
                  *
                  * @jboss:table-name table-name = "user"
                  *
                  * @jboss:create-table "true"
                  *
                  **/