10 Replies Latest reply on Jun 29, 2005 3:25 PM by darranl

    Jboss 4.02 CMP EntityBean. JBoss creates TABLES in MySQL sch

    natgross

      Hi;
      A local entity cmp bean called from a session bean (facade pattern) in the same jar:
      When deploying the bean JBoss creates a new table in the MySql schema with "Bean" appended to table name. A very simple 2 column table (int, string. The int is the pk.), MyTable, has an entity bean mapped to it. Upon deployment JBoss creates a "MyTableBean" table in the same schema, and all finders do SELECTS on this table, which always comes up empty, of course.
      Even though the ejbQL is on "MyTable", the MySql log shows JBoss' SELECTS on the "MyTableBean" table.
      What does this symptom mean?
      (JBoss 4.0.2 on Linux FC3.)
      Thank you;
      -nat

        • 1. Re: Jboss 4.02 CMP EntityBean. JBoss creates TABLES in MySQL
          darranl

          Have you got a jbosscmp-jdbc.xml deployment descriptor being deployed with your entity bean? Inside that deployment descriptor you can specify the name that should be used for the table in a <table-name> element within the element.

          The name within the EJB-QL is the name of the EJB which is not allways the same as the table name, this is left to the container to convert to the appropriate table name.



          • 2. Re: Jboss 4.02 CMP EntityBean. JBoss creates TABLES in MySQL
            natgross

             

            "darranl" wrote:
            Have you got a jbosscmp-jdbc.xml deployment descriptor being deployed with your entity bean?

            Yes. I copied the standardjbosscmp-jdbc.xml over and modified the datasource, leaving all other settings the same. (It is using the correct datasource per this file.)


            Inside that deployment descriptor you can specify the name that should be used for the table in a <table-name> element within the <entity> element.

            Oh! I don't HAVE any entity sections. Will need to google for the exact, layout. I guess. Or, if it takes <30 seconds maybe you want to link or paste the MINIMUM required for this to function.

            The name within the EJB-QL is the name of the EJB which is not allways the same as the table name, this is left to the container to convert to the appropriate table name.

            THAT I would never had guessed.
            Thank you much!
            -nat

            • 3. Re: Jboss 4.02 CMP EntityBean. JBoss creates TABLES in MySQL
              darranl

              If you have a look in the docs folder of your JBoss installation you will find a dtd and schema folder, these two folders contain the dtd's and schemas that describe the layouts of the various deployment descriptors. This is the best place to start when trying to work out the structure of the file.

              Below is an example jbosscmp-jdbc.xml based on one from the JBoss testsuite (I have made some minor changes but it should be a valid file) : -

              <?xml version="1.0" encoding="UTF-8"?>
              
              <!DOCTYPE jboss PUBLIC
               "-//JBoss//DTD JBOSS 4.0//EN"
               "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">
              
              <jbosscmp-jdbc>
               <defaults>
              
               <datasource>java:/MySqlDS</datasource>
               <datasource-mapping>mySQL</datasource-mapping>
              
               <create-table>true</create-table>
               <remove-table>true</remove-table>
              
               </defaults>
              
               <enterprise-beans>
              
               <entity>
               <ejb-name>SimpleEJB</ejb-name>
               <table-name>SimpleA</table-name>
               </entity>
              
               </enterprise-beans>
              </jbosscmp-jdbc>
              


              You don't need the majority of the data from the 'standardjbosscmp-jdbc.xml', JBoss uses the settings from the 'standardjbosscmp-jdbc.xml' unless it has been overriden in the deployment specific 'jbosscmp-jdbc.xml'.

              • 4. Re: Jboss 4.02 CMP EntityBean. JBoss creates TABLES in MySQL
                natgross

                Thank you very much!
                Hope to report with success soon.
                -nat

                • 5. Re: Jboss 4.02 CMP EntityBean. JBoss creates TABLES in MySQL
                  natgross

                  . alas... no go.
                  Please, here is a copy of my ejb-jar.xml. (The name of the sql table is `TypeG`.)

                  <?xml version="1.0" encoding="UTF-8"?>
                  <ejb-jar version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
                  http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
                  
                   <display-name>ZTypeG2</display-name>
                   <enterprise-beans>
                   <session>
                   <display-name>TypeGfacadeSB</display-name>
                   <ejb-name>TypeGfacadeBean</ejb-name>
                   <home>dbTest.TypeGfacadeRemoteHome</home>
                   <remote>dbTest.TypeGfacadeRemote</remote>
                   <ejb-class>dbTest.TypeGfacadeBean</ejb-class>
                   <session-type>Stateful</session-type>
                   <transaction-type>Container</transaction-type>
                   <ejb-local-ref>
                   <ejb-ref-name>ejb/TypeGBean</ejb-ref-name>
                   <ejb-ref-type>Entity</ejb-ref-type>
                   <local-home>dbTest.TypeGLocalHome</local-home>
                   <local>dbTest.TypeGLocal</local>
                   <ejb-link>TypeGBean</ejb-link>
                   </ejb-local-ref>
                   </session>
                   <entity>
                   <description>TypeG Entity Bean.</description>
                   <display-name>TypeGEB</display-name>
                   <ejb-name>TypeGBean</ejb-name>
                   <local-home>dbTest.TypeGLocalHome</local-home>
                   <local>dbTest.TypeGLocal</local>
                   <ejb-class>dbTest.TypeGBean</ejb-class>
                   <persistence-type>Container</persistence-type>
                   <prim-key-class>java.lang.Integer</prim-key-class>
                   <reentrant>false</reentrant>
                   <abstract-schema-name>TypeG</abstract-schema-name>
                   <cmp-field>
                   <field-name>id</field-name>
                   </cmp-field>
                   <cmp-field>
                   <field-name>valueType</field-name>
                   </cmp-field>
                   <primkey-field>id</primkey-field>
                   <query>
                   <description>find By Id</description>
                   <query-method>
                   <method-name>findById</method-name>
                   <method-params>
                   <method-param>java.lang.Integer</method-param>
                   </method-params>
                   </query-method>
                   <ejb-ql>SELECT OBJECT(t) FROM TypeG AS t WHERE t.id = ?1</ejb-ql>
                   </query>
                   <query>
                   <description>findByValueType</description>
                   <query-method>
                   <method-name>findByValueType</method-name>
                   <method-params>
                   <method-param>java.lang.String</method-param>
                   </method-params>
                   </query-method>
                   <ejb-ql>SELECT OBJECT(t) FROM TypeG AS t WHERE t.valueType = ?1</ejb-ql>
                   </query>
                   <query>
                   <query-method>
                   <method-name>findAll</method-name>
                   <method-params/>
                   </query-method>
                   <ejb-ql>SELECT OBJECT(o) FROM TypeG o</ejb-ql>
                   </query>
                   </entity>
                   </enterprise-beans>
                   <assembly-descriptor>
                   <container-transaction>
                   <method>
                   <ejb-name>TypeGBean</ejb-name>
                   <method-name>*</method-name>
                   </method>
                   <trans-attribute>Required</trans-attribute>
                   </container-transaction>
                   <container-transaction>
                   <method>
                   <ejb-name>TypeGfacadeBean</ejb-name>
                   <method-name>*</method-name>
                   </method>
                   <trans-attribute>Required</trans-attribute>
                   </container-transaction>
                   </assembly-descriptor>
                  </ejb-jar>
                  


                  And the relevant records from the jbosscmp-jdbc.xml:
                  <enterprise-beans>
                   <entity>
                   <ejb-name>TypeGBean</ejb-name>
                   <table-name>TypeG</table-name>
                   </entity>
                   </enterprise-beans>
                  


                  Again, Thank you much.
                  -nat


                  • 6. Re: Jboss 4.02 CMP EntityBean. JBoss creates TABLES in MySQL
                    darranl

                    Sorry, I have just double checked and I made a mistake regarding the name to use within the query.

                    The <abstract-schema-name> is the value to use in the query not the bean name, this value is just used within the queries. Some people reccomend that you keep this the same as your bean name, that is where I had the two back to front. Your descriptors are using the abstract-schema-name in the query so that is Ok.

                    What is happening now when you deploy it? Are you getting an error or is it just that it is still creating a table called 'TypeGBean'.

                    If there is an error could you post it here. If it is still using the wrong table name can you double check the 'jbosscmp-jdbc.xml' is in your archive in the same place as the other deployment descriptors.

                    • 7. Re: Jboss 4.02 CMP EntityBean. JBoss creates TABLES in MySQL
                      natgross

                      Maybe it was pickin up the old jbosscmp-jdbc.xml because I just did a 'clean' rebuild, redploy and now its complaining about the jbosscmp-jdbc.xml (I lifted it out of your post.)

                      Error message: Document root element "jbosscmp-jdbc", must match DOCTYPE root "jboss".


                      Seems like I need to study the dtd. Or maybe, since I have abstract-schema defined in ejb-jar.xml, the only thing I need in jbosscmp-jdbc.xml is the datasource.

                      Thanks again;
                      -nat


                      • 8. Re: Jboss 4.02 CMP EntityBean. JBoss creates TABLES in MySQL
                        natgross

                        Maybe it was pickin up the old jbosscmp-jdbc.xml because I just did a 'clean' rebuild, redploy and now its complaining about the jbosscmp-jdbc.xml (I lifted it out of your post.)

                        Error message: Document root element "jbosscmp-jdbc", must match DOCTYPE root "jboss".


                        Seems like I need to study the dtd. Or maybe, since I have abstract-schema defined in ejb-jar.xml, the only thing I need in jbosscmp-jdbc.xml is the datasource.

                        Thanks again;
                        -nat


                        • 9. Re: Jboss 4.02 CMP EntityBean. JBoss creates TABLES in MySQL
                          natgross

                          Darranal, It's working!
                          I just had to change the DOCTYPE in your post from 'jboss' to 'jbosscmp-jdbc'.

                          Thanks again;
                          -nat

                          • 10. Re: Jboss 4.02 CMP EntityBean. JBoss creates TABLES in MySQL
                            darranl

                            Yes, sorry it was late when I was replying to your posts, the full DOCTYPE should be: -

                             <!DOCTYPE jbosscmp-jdbc PUBLIC
                             "-//JBoss//DTD JBOSSCMP-JDBC 4.0//EN"
                             "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_4_0.dtd">