2 Replies Latest reply on Jul 30, 2002 6:52 AM by ruu

    sql-statement problem with xdocklet and mySQL

    ruu Newbie

      Hi all,

      I'm having problems to deploy a simple Address entity bean. I'm using xdoclet and mySQL 4.0. Address should be an EJB 2.0 local entity with cmp.

      I'm adding some file content which I consider as possibly
      helpful. The most important question for me is located at the end of this text.

      Maybe somebody can help me without reading all those lines below.

      Here is my ejb:

      -------------------------------------------------------------------------------
      package test.ejb.server;

      import util.UUIDUtil;

      import javax.ejb.*;

      /**
      * @ejb:bean name ="test.ejb.server.Address"
      * jndi-name ="test.ejb.server.AddressHome"
      * local-jndi-name="test.ejb.server.AddressHome"
      * view-type ="local"
      * type ="CMP"
      * cmp-version ="2.x"
      * schema ="test.ejb.server.Address"
      * primkey-field ="id"
      * @ejb:finder signature="Collection findAll()"
      * @ejb:interface name ="test.ejb.server.Address"
      * @ejb:pk class ="java.lang.String"
      * generate ="true"
      *
      * @jboss:table-name address
      * create-table true
      * remove-table true
      * read-only false
      */
      public abstract class AddressBean implements EntityBean
      {
      private EntityContext ctx = null;

      /**
      * @ejb:interface-method
      * @ejb:pk-field
      * @ejb:persistent-field
      *
      * @jboss:cmp-field field-name ="id"
      * column-name="id"
      * @jboss:column-name id
      * @jboss:jdbc-type VARCHAR
      * @jboss:sql-type VARCHAR(32)
      */
      public abstract String getId();
      /**
      * do not expose to interface, setting ids is not allowed from outside the bean
      */
      public abstract void setId(String id);

      /**
      * @ejb:interface-method
      * @ejb:persistent-field
      *
      * @jboss:cmp-field field-name ="street"
      * column-name="street"
      * @jboss:jdbc-type VARCHAR
      * @jboss:sql-type VARCHAR(50)
      */
      public abstract String getStreet();
      /**
      * @ejb:interface-method
      */
      public abstract void setStreet(String street);

      /**
      * @ejb:interface-method
      * @ejb:persistent-field
      *
      * @jboss:cmp-field field-name ="city"
      * column-name="city"
      * @jboss:jdbc-type VARCHAR
      * @jboss:sql-type VARCHAR(50)
      */
      public abstract String getCity();
      /**
      * @ejb:interface-method
      */
      public abstract void setCity(String city);

      public void ejbActivate()
      {
      }

      public void ejbPassivate()
      {
      }

      /**
      * @ejb:create-method
      */
      public String ejbCreate(String street, String city) throws CreateException
      {
      this.setId(UUIDUtil.instance().getUUID());

      this.setStreet(street);
      this.setCity( city);

      return null;
      }

      public void ejbPostCreate(String street, String city)
      {
      }

      public void ejbRemove() throws RemoveException
      {
      }

      public void setEntityContext(EntityContext ctx)
      {
      this.ctx = ctx;
      }

      public void unsetEntityContext()
      {
      this.ctx = null;
      }
      }
      -------------------------------------------------------------------------------

      The first thing that seems strange to me is the following:

      If I run ejbdoclet it says:

      Message=[In element "entity" ist hier "local-jndi-name" nicht zulõssig.] is not
      valid according to its DTD

      (translation: in element "entity" "local-jndi-name" is not allowed)

      I'm not sure if it is a problem to put an entity in different jndi trees using
      the same name. (This is what I meant to do when I defined the local-jndi-name
      and jndi-name attributes in the file above. Maybe it's not a good idea?)

      ejbdoclet doesn't generate a jaws.xml nor a jbosscmp-jdbc.xml file. But even
      if delete the local-jndi-name attribute in the file the message doesn't
      disappear!?

      Surprisingly if I run ejbdoclet again immediately it generates a jaws.xml-file
      (but still no jbosscmp-jdbc.xml) and says:

      Message=[In Element "cmp-field" ist hier "sql-type" nicht zulõssig.] is not
      valid according to its DTD
      (translation: in element "cmp-field" "sql-type" is not allowed)

      If I delete the @jboss:sql-type tags it says "cmp-field requires additional
      elements". What does ejbdoclet want me to do?

      jbosscmp-jdbc.xml is still not generated.

      If I then run ejbdoclet again immediately it generates a jbosscmp-jdbc.xml and
      terminates without further complaints. Here is what I get:

      jaws.xml ----------------------------------------------------------------------
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jaws PUBLIC "-//JBoss//DTD JAWS 3.0//EN" "http://www.jboss.org/j2ee/dtd/jaws_3_0.dtd">

      <jaws>
      <datasource>java:/ruudatasource</datasource>
      <type-mapping>mySQL</type-mapping>

      <enterprise-beans>

      <entity>
      <ejb-name>test.ejb.server.Address</ejb-name>

      <cmp-field>
      <field-name>city</field-name>
      <column-name>city</column-name>
      <sql-type>VARCHAR(50)</sql-type>
      <jdbc-type>VARCHAR</jdbc-type>

      </cmp-field>
      <cmp-field>
      <field-name>id</field-name>
      <column-name>id</column-name>
      <sql-type>VARCHAR(32)</sql-type>
      <jdbc-type>VARCHAR</jdbc-type>

      </cmp-field>
      <cmp-field>
      <field-name>street</field-name>
      <column-name>street</column-name>
      <sql-type>VARCHAR(50)</sql-type>
      <jdbc-type>VARCHAR</jdbc-type>

      </cmp-field>

      <table-name>address create-table false remove-table false read-only false</table-name>
      <row-locking></row-locking>

      </entity>

      </enterprise-beans>

      </jaws>
      -------------------------------------------------------------------------------

      jbosscmp-jdbc.xml--------------------------------------------------------------
      <?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>
      <defaults>
      <datasource>java:/ruudatasource</datasource>
      <datasource-mapping>mySQL</datasource-mapping>
      </defaults>

      <enterprise-beans>

      <entity>
      <ejb-name>test.ejb.server.Address</ejb-name>
      <table-name>address create-table false remove-table false read-only false</table-name>

      <cmp-field>
      <field-name>city</field-name>
      <column-name>city</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(50)</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>id</field-name>
      <column-name>id</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(32)</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>street</field-name>
      <column-name>street</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(50)</sql-type>

      </cmp-field>
      <!--
      To define load groups for this entity, write a file named
      jbosscmp-jdbc-load-AddressBean.xml and put it in
      your mergedir. Write it according to the following DTD slice:
      <!ELEMENT load-groups (load-group+)>
      <!ELEMENT load-group (load-group-name, description?, field-name+)>
      <!ELEMENT load-group-name (#PCDATA)>
      <!ELEMENT description (#PCDATA)>
      <!ELEMENT field-name (#PCDATA)>
      <!ELEMENT eager-load-group (#PCDATA)>
      <!ELEMENT lazy-load-groups (load-group-name+)>
      -->

      </entity>

      </enterprise-beans>

      <dependent-value-classes>

      </dependent-value-classes>

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

      If I build a jar now, drop it into the deploy directory and start jboss it
      fails deploying my address-bean. It tries to create a table and obviously
      uses a statement with invalid syntax similar to the following:

      CREATE TABLE address create-_15qn3yj (id VARCHAR(32) NOT NULL, street VARCHAR(50), city VARCHAR(50), CONSTRAINT pk_address crea_1mwi3go PRIMARY KEY (id))

      Why is that "create-_15qn3yj" and "crea_1mwi3go" stuff in the statement?

      Thanks a lot for any kind of help,

      Roger

        • 1. Re: sql-statement problem with xdocklet and mySQL
          cdmdev Newbie

          Are you using CMP? I assume so, the container takes the EJB-SQL and translates it to SQL for your database, they put their own var names in there. I would start by looking at your ejb-jar.xml file and make sure you have correct EJB-SQL statements.

          • 2. Re: sql-statement problem with xdocklet and mySQL
            ruu Newbie

            I'm not sure if I understand what you said. I know ejb-ql and I used it for queries. But what do you mean by ejb-sql? Should there be one or more ejb-sql-section(s) in my ejb-jar.xml?

            My idea is to let xdoclet / ejbdoclet generate all my deployment descriptors. I hope not to have to manipulate them manually. This should be possible, shouldn't it?

            Anyhow, here is my ejb-sql:

            <?xml version="1.0" encoding="UTF-8"?>
            <!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 >

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

            <enterprise-beans>

            <!-- Session Beans -->

            <![CDATA[No Description.]]>

            <ejb-name>de.test.ejb.server.StatelessSession</ejb-name>

            de.test.ejb.server.StatelessSessionHome
            de.test.ejb.server.StatelessSession
            <ejb-class>de.test.ejb.server.StatelessSessionBean</ejb-class>
            <session-type>Stateless</session-type>
            <transaction-type>Container</transaction-type>



            <!--
            To add session beans that you have deployment descriptor info for, add
            a file to your merge directory called session-beans.xml that contains
            the markup for those beans.
            -->

            <!-- Entity Beans -->

            <![CDATA[No Description.]]>
            <display-name>de.test.ejb.server.Address</display-name>

            <ejb-name>de.test.ejb.server.Address</ejb-name>

            <local-home>de.test.ejb.server.AddressHome</local-home>
            de.test.ejb.server.Address

            <ejb-class>de.test.ejb.server.AddressBean</ejb-class>
            <persistence-type>Container</persistence-type>
            <prim-key-class>java.lang.String</prim-key-class>
            False
            <cmp-version>2.x</cmp-version>
            <abstract-schema-name>de.test.ejb.server.Address</abstract-schema-name>
            <cmp-field >
            <![CDATA[]]>
            <field-name>id</field-name>
            </cmp-field>
            <cmp-field >
            <![CDATA[]]>
            <field-name>street</field-name>
            </cmp-field>
            <cmp-field >
            <![CDATA[]]>
            <field-name>city</field-name>
            </cmp-field>
            <primkey-field>id</primkey-field>



            <!--
            To add entity beans that you have deployment descriptor info for, add
            a file to your merge directory called entity-beans.xml that contains
            the markup for those beans.
            -->

            <!-- Message Driven Beans -->
            <!--
            To add message driven beans that you have deployment descriptor info for, add
            a file to your merge directory called message-driven-beans.xml that contains
            the <message-driven></message-driven> markup for those beans.
            -->

            </enterprise-beans>

            <!-- Relationships -->

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

            <!-- finder permissions -->

            <!-- finder permissions -->

            <!-- transactions -->

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

            </ejb-jar>