4 Replies Latest reply on Oct 16, 2003 4:15 AM by prafullan

    Error parsing ejb-ql

    prafullan

      Hello all ,

      I am new to JBoss . I am trying to build a CMP entity Bean .I am using Mastering Enterprise JavaBeans book of Ed Roman ,example for it ProductBean enitity Bean with CMP . When deploying , i am getting parser error for ejb-ql syntax
      <ejb-ql>
      <! [CDATA[ SELECT OBJECT(a) FROM ProductBean AS a WHERE productId IS NOT NULL ]] >
      </ejb-ql>

      error :
      --------
      org.xml.sax.SaxParseException : "<!"

      at org.apache.crimson.parser.Parser2.fatal() etc ...

      I am using jboss-3.0.0RC1_tomcat-4.0.3 .

      Can any one help me solve this problem .

      Thanks

      prafullan


      My remote interface is :
      ------------------------------
      public interface Product extends EJBObject
      {
      public void setName(String name) throws RemoteException ;
      public String getName() throws RemoteException ;
      public void setDescription(String desc) throws RemoteException ;
      public String getDescription() throws RemoteException ;
      public void setBasePrice(double price) throws RemoteException ;
      public double getBasePrice() throws RemoteException ;

      public String getProductId() throws RemoteException ;
      }

      My entity Bean issome what like shown below:
      ----------------------------------------------------------
      public abstract class ProductBean implements EntityBean
      {
      private EntityContext ctxt = null ;

      /* Abstract Methods */

      public abstract void setProductId(String productId);
      public abstract void setName(String name);
      public abstract void setDescription(String desc);
      public abstract void setBasePrice(double price);
      public abstract String getProductId();
      public abstract String getName();
      public abstract String getDescription();
      public abstract double getBasePrice();

      public void setEntityContext(EntityContext ctxt)
      {
      this.ctxt = ctxt;
      }
      public void unsetEntityContext()
      {
      this.ctxt = null;
      }
      public ProductPK ejbCreate(String productId ,String name,String desc,double price)
      throws CreateException
      {
      System.out.println(" CMP EntityBean ejbCreate");
      setProductId(productId);
      setName(name);
      setDescription(desc);
      setBasePrice(price);
      return new ProductPK(productId);

      }
      // other ejb methods here .
      }

      ejb-jar file given below :
      -------------------------------
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
      "http://java.sun.com/j2ee/dtd/ejb-jar_2_0.dtd">
      <ejb-jar>
      My sample HelloWorld EJBforJBOSS
      <display-name>Hello World EJB </display-name>

      <enterprise-beans>

      <ejb-name>Product</ejb-name>
      com.myEjb.sample.ProductHome
      com.myEjb.sample.Product
      <local-home>com.myEjb.sample.ProductLocalHome</local-home>
      com.myEjb.sample.ProductLocal
      <ejb-class>com.myEjb.sample.ProductBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>com.myEjb.sample.ProductPK</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>ProductBean</abstract-schema-name>
      <cmp-field>
      <field-name>productId</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>name</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>description</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>basePrice</field-name>
      </cmp-field>

      <query-method>
      <method-name>findAllProducts</method-name>
      <method-params>
      </method-params>
      </query-method>
      <ejb-ql>
      <! [CDATA[ SELECT OBJECT(a) FROM ProductBean AS a WHERE productId IS NOT NULL ]] >
      </ejb-ql>



      </enterprise-beans>
      </ejb-jar>

      jbosscmp-jdbc.xml file is :
      --------------------------------
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN"
      "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">
      <jbosscmp-jdbc>
      <enterprise-beans>

      <ejb-name>Product</ejb-name>
      <remove-table>product</remove-table>
      <table-name>product</table-name>
      <cmp-field>
      <field-name>productId</field-name>
      <column-name>id</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>name</field-name>
      <column-name>name</column-name>
      <not-null/>
      </cmp-field>
      <cmp-field>
      <field-name>description</field-name>
      <column-name>description</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(64)</sql-type>
      </cmp-field>
      <cmp-field>
      <field-name>basePrice</field-name>
      <column-name>price</column-name>
      <jdbc-type>DOUBLE</jdbc-type>
      <sql-type>FLOAT</sql-type>
      </cmp-field>

      </enterprise-beans>
      </jbosscmp-jdbc>

        • 1. Re: Error parsing ejb-ql
          benwalstrum

          You have two problems as I see it. First, the DOCTYPE is referencing either an old resource, or just the incorrect resource for ejb-jar.xml. It should be

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

          That may or may not cause problems, but it made it difficult for me to validate the XML. Second, and most importantly, the main problem is with your CDATA block itself. In order for a CDATA block to be well-formed in XML it must be of the format <![CDATA[]]>.
          Most important to note is that you can't have any whitespace between "<!" and "[", which is what you had ("<! ["). Also there cannot be any whitespace between "]" and ">" at the end, which is also what you had ("] >"). That should fix the validation problem, and also makes sense of the error message that you recieved.

          Regards,

          Ben

          • 2. Re: Error parsing ejb-ql
            prafullan

            Thanks benwalstrum ,

            You are correct . It is the problem with space between <! and CDATA , that was giving the problem . I trimmed the spaces , now it is working fine .

            Thanks for the prompt response Ben . Sure this is a really great forum then .

            Ben is there a way i can describe the database where i want the entity bean to be persist . Default is hypersonic i believe . If i want data to persist on sqlServer or Oracle what should i do ?


            Thanks & Regards

            Rakesh



            • 3. Re: Error parsing ejb-ql
              benwalstrum

              Getting your beans to persist to a specified database is a two step process.

              First, you must set up a *-ds.xml file which will define your connection to the database as well as the datasource (jndi) name. Examples can be found in the docs/examples/jca subdirectory of your distribution (Note: the steps I am giving you are a little different if you are not using 3.2.x - but you should be using 3.2.1 or 3.2.2 because they are far superior to the 3.0.x builds). Take one of those files, copy it to the deploy directory, and configure it with the correct values.

              Once that step is done you have two ways of telling your entity beans to use that datasource. The first is to modify the datasoure in the standardjaws.xml and standardjbosscmp-jdbc.xml (it's at the very top). This has the effect of setting the default datasource for the system to your new datasource. Also, you will want to modify the datasource-mapping which tells JBoss what type of data source to use (the type mappings are enumerated throughout the rest of the file).

              While the above approach will work, it is not necessarily the best approach in all situations. I have found that it is easiest to leave the standardjaws.xml and standardjbosscmp-jdbc.xml alone (letting them remain configured to Hypersonic) and to put the configuration into the EJBs themselves. This is done through the jbosscmp-jdbc.xml file. At the top you can add a section that looks like this:

              ...
              <jbosscmp-jdbc>

              java:/OracleDS
              <datasource-mapping>Oracle</datasource-mapping>

              <enterprise-beans>
              ...

              This sets the default datasource mapping for the beans (you can also set the datasource for individual EJBs as well). Note that the datasource-mapping is one of the entries from the standardjbosscmp.jdbc file mentioned above. I like this approach as it doesn't involve changing the default configuration.

              Hope this helps.

              Ben

              • 4. Re: Error parsing ejb-ql
                prafullan

                Thanks benwalstrum ,

                That solved my problem . I was able to persist data to SQLServer2000 .

                Thanks

                rakesh