1 Reply Latest reply on Mar 6, 2005 4:36 PM by Frank Langelage

    CMP error Can't parse EJB-QL statement

    Tushar Patel Newbie

      Hi

      I have a very simple CMP 2.0 bean where the finder method will not parse and I almost 100% correct. I will post all of the relevant code and the exepction if anyone can help that would be great.

      Platform
      ----------
      JBoss 4.0.1
      Win2000 Pro
      IDE Eclipse
      Postgres 7.4

      ---------------------------------------------------------------------------------------------------------------------------------------------
      Member table
      create table members
      (
      member_id integer primary key default nextval('seq_uid'),
      member_number varchar(50),
      access_authorization_id integer,
      last_name varchar(50),
      first_name varchar(50),
      middle_initial varchar(50),
      company_name varchar(50),
      email varchar(50),
      created_by varchar(50),
      created_datetime timestamp,
      modified_by varchar(50),
      modified_datetime timestamp,
      active_ind boolean,
      valid_ind boolean
      );

      ------------------------------------------------------------------------------------------------------------------------------------------------------------------
      jbosscmp-jdbc.xml
      -----------------------
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 4.0//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_4_0.dtd">

      <jbosscmp-jdbc>

      java:/jdbc/PostgresSS
      <datasource-mapping>PostgreSQL 7.2</datasource-mapping>
      <create-table>false</create-table>
      <remove-table>false</remove-table>


      <enterprise-beans>

      <ejb-name>Member</ejb-name>
      <table-name>members</table-name>

      <cmp-field>
      <field-name>memberId</field-name>
      <column-name>member_id</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>memberNumber</field-name>
      <column-name>member_number</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>lastName</field-name>
      <column-name>last_name</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>firstName</field-name>
      <column-name>first_name</column-name>
      </cmp-field>

      <!-- jboss 3.2 features -->
      <!-- optimistic locking does not express the exclusions needed -->


      </enterprise-beans>

      </jbosscmp-jdbc>
      ------------------------------------------------------------------------------------------------------------------------------------------------

      ejb-jar.xml
      ------------------------------------------------------
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">

      <ejb-jar >

      [CDATA[No Description.]]
      <display-name>Generated by XDoclet</display-name>

      <enterprise-beans>

      <!-- Entity Beans -->

      [CDATA[Description for Member]]
      <display-name>Name for Member</display-name>

      <ejb-name>Member</ejb-name>

      <local-home>com.ufa.petro.ss.services.member.MemberLocalHome</local-home>
      com.ufa.petro.ss.services.member.MemberLocal

      <ejb-class>com.ufa.petro.ss.services.member.MemberBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Members</abstract-schema-name>

      <cmp-field>
      <field-name>memberId</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>memberNumber</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>lastName</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>firstName</field-name>
      </cmp-field>


      <query-method>
      <method-name>findByLastName</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <ejb-ql>
      [CDATA[ SELECT OBJECT(o) FROM Members AS o WHERE o.lastName = ?1 ]]
      </ejb-ql>

      <!-- Write a file named ejb-finders-MemberBean.xml if you want to define extra finders. -->


      </enterprise-beans>

      <!-- Relationships -->

      <!-- Assembly Descriptor -->
      <assembly-descriptor >

      <!-- finder permissions -->

      <!-- transactions -->

      <!-- finder transactions -->
      </assembly-descriptor>

      </ejb-jar>

      --------------------------------------------------------------------------------------------------------------------------------------------------

      MemberLocal.java
      --------------------
      package com.ufa.petro.ss.services.member;

      /**
      * Local interface for Member.
      */
      public interface MemberLocal
      extends javax.ejb.EJBLocalObject
      {
      String getFirstName();
      String getLastName();
      }

      -----------------------------------------------------------------------------------------------------------------------------------------
      MemberLocalHome.java
      -----------------------------
      package com.ufa.petro.ss.services.member;

      import java.util.Collection;

      /**
      * Local home interface for Member.
      */
      public interface MemberLocalHome
      extends javax.ejb.EJBLocalHome
      {
      public static final String COMP_NAME="java:comp/env/ejb/MemberLocal";
      public static final String JNDI_NAME="MemberLocal";

      public Collection findByLastName(String i) throws javax.ejb.FinderException;

      public MemberLocal findByPrimaryKey(Integer id) throws javax.ejb.FinderException;

      }
      -------------------------------------------------------------------------------------------------------------------------------------------
      MemberBean.java
      ------------------------

      public abstract class MemberBean implements EntityBean {

      public MemberBean() {
      super();
      // TODO Auto-generated constructor stub
      }

      public void setEntityContext(EntityContext ctx)
      throws EJBException,
      RemoteException {
      // TODO Auto-generated method stub

      }

      public void unsetEntityContext() throws EJBException, RemoteException {
      // TODO Auto-generated method stub

      }

      public void ejbRemove()
      throws RemoveException,
      EJBException,
      RemoteException {
      // TODO Auto-generated method stub

      }

      public void ejbActivate() throws EJBException, RemoteException {
      // TODO Auto-generated method stub

      }

      public void ejbPassivate() throws EJBException, RemoteException {
      // TODO Auto-generated method stub

      }

      public void ejbLoad() throws EJBException, RemoteException {
      // TODO Auto-generated method stub

      }
      public void ejbStore() throws EJBException, RemoteException {
      // TODO Auto-generated method stub

      }

      public abstract Integer getMemberId();
      public abstract void setMemberId(Integer id);
      public abstract String getMemberNumber();
      public abstract void setMemberNumber(String memberNumber);
      public abstract String getLastName();
      public abstract void setLastName(String lastName);
      public abstract String getFirstName();
      public abstract void setFirstName(String firstName);
      }
      -------------------------------------------------------------------------------------------------------------------------------------------------------
      Exception Stack trace
      ----------------

      15:45:30,235 INFO [EARDeployer] Started J2EE application: file:/D:/Projects/UFA/Pace_Phase_II/Development/jboss-4.0.1/server/default/deploy/SelfService.ear
      15:45:33,389 ERROR [Member#findByLastName] Find failed
      java.sql.SQLException: ERROR: parser: parse error at or near "FROM" at character 9
      at org.postgresql.core.QueryExecutor.executeV2(QueryExecutor.java:289)
      at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:105)
      at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:43)
      at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:515)
      at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:50)
      at org.postgresql.jdbc1.AbstractJdbc1Statement.executeQuery(AbstractJdbc1Statement.java:231)
      at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:296)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractQueryCommand.execute(JDBCAbstractQueryCommand.java:206)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractQueryCommand.execute(JDBCAbstractQueryCommand.java:128)

      ---------------------------------------------------------------------------------------------------
      Here is the client code I'm using to access the finder method


      try {
      Context context = new InitialContext();

      MemberLocalHome home = (MemberLocalHome) context
      .lookup(MemberLocalHome.JNDI_NAME);
      Collection members = home.findByLastName("Patel");
      Iterator i = members.iterator();
      while (i.hasNext()) {
      MemberLocal member = (MemberLocal) i.next();
      System.out.println("************* "
      + member.getFirstName());
      }
      } catch (Exception e) {
      e.printStackTrace();
      }

        • 1. Re: CMP error Can't parse EJB-QL statement
          Frank Langelage Master

           

          15:45:33,389 ERROR [Member#findByLastName] Find failed
          java.sql.SQLException: ERROR: parser: parse error at or near "FROM" at character 9
          at org.postgresql.core.QueryExecutor.executeV2(QueryExecutor.java:289)
          at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:105)
          at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:43)
          at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:515)
          at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:50)
          at org.postgresql.jdbc1.AbstractJdbc1Statement.executeQuery(AbstractJdbc1Statement.java:231)
          at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:296)
          at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractQueryCommand.execute(JDBCAbstractQueryCommand.java:206)
          at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractQueryCommand.execute(JDBCAbstractQueryCommand.java:128)

          The SQL generated by jboss is not correct for postgresql.
          Look into $JBOSS_HOME/server/?/log/server.log and show us the failing sql.