9 Replies Latest reply on Nov 1, 2002 1:43 PM by dean_tanabe

    ejbPostCreate method is not being called, any ideas?

    dean_tanabe

      Hello,

      I have two entity beans in a 1-M relationship. It works fine when retrieving data, but it seems that the ejbPostCreate method for either bean is not being called when I try to add a new row through the bean using the create method.

      I tried testing it with just some general output statements like the following. The statement in the ejbCreate method is shown, but not the one from the ejbPostCreate method. No exceptions seem to be thrown or at least none show up in the logs or the console and the row is added to the database. Anyone have any ideas to what I'm doing wrong?

      example:

      ejbCreate(String bleh) throws CreateException {
      System.out.println("** ejbCreate called");
      setBleh(bleh);
      }

      ejbPostCreate(String bleh) {
      System.out.println("** ejbPostCreate called");
      }

      Much Aloha,
      Dean

        • 1. Re: ejbPostCreate method is not being called, any ideas?
          tdang

          Which version of JBoss do you use? JBoss 3.0.1 seems to be very stable for 1-M relationship purposes. If you are using JBoss under 3.0.1, it is recommended to download the new version on SF.

          Hope it helps.

          • 2. Re: ejbPostCreate method is not being called, any ideas?
            dean_tanabe

            hrm, I'm using 3.0.2 at the moment. I'll give 3.0.1 a shot.. Much thanks

            Much Aloha,
            Dean

            • 3. Re: ejbPostCreate method is not being called, any ideas?
              dean_tanabe

              I have had the same results using version 3.0.1. I thought I'd post the ejb-jar.xml and jbosscmp-jdbc.xml files and the create methods for the beans in hopes that someone can tell me where my error is. I'm using JBoss version 3.0.2 and mysql 3.23.52

              EJB-JAR.XML

              <?xml version="1.0"?>
              <!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>
              <enterprise-beans>

              <ejb-name>BmEmployee</ejb-name>
              <local-home>bm.ejb.BmEmployeeLocalHome</local-home>
              bm.ejb.BmEmployeeLocal
              <ejb-class>bm.ejb.BmEmployeeEJB</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>BmEmployee</abstract-schema-name>
              <cmp-field><field-name>empPk</field-name></cmp-field>
              <cmp-field><field-name>firstName</field-name></cmp-field>
              <cmp-field><field-name>lastName</field-name></cmp-field>
              <primkey-field>empPk</primkey-field>
              <ejb-local-ref>
              <ejb-ref-name>ejb/BmEmployeeNumberLocal</ejb-ref-name>
              <ejb-ref-type>Entity</ejb-ref-type>
              <local-home>bm.ejb.BmEmployeeNumberLocalHome</local-home>
              bm.ejb.BmEmployeeNumberLocal
              <ejb-link>BmEmployeeNumber</ejb-link>
              </ejb-local-ref>


              <ejb-name>BmEmployeeNumber</ejb-name>
              <local-home>bm.ejb.BmEmployeeNumberLocalHome</local-home>
              bm.ejb.BmEmployeeNumberLocal
              <ejb-class>bm.ejb.BmEmployeeNumberEJB</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>BmEmployeeNumber</abstract-schema-name>
              <cmp-field><field-name>phonePk</field-name></cmp-field>
              <cmp-field><field-name>phoneNumber</field-name></cmp-field>
              <primkey-field>phonePk</primkey-field>

              </enterprise-beans>


              <ejb-relation>
              <ejb-relation-name>Employee-PhoneNumbers</ejb-relation-name>
              <ejb-relationship-role>
              <ejb-relationship-role-name>
              BmEmployee-has-BmEmployeeNumbers
              </ejb-relationship-role-name>
              One
              <relationship-role-source>
              <ejb-name>BmEmployee</ejb-name>
              </relationship-role-source>
              <cmr-field>
              <cmr-field-name>phoneNumbers</cmr-field-name>
              <cmr-field-type>java.util.Collection</cmr-field-type>
              </cmr-field>
              </ejb-relationship-role>
              <ejb-relationship-role>
              <ejb-relationship-role-name>
              BmEmployeeNumber-belongs-to-BmEmployee
              </ejb-relationship-role-name>
              Many
              <cascade-delete />
              <relationship-role-source>
              <ejb-name>BmEmployeeNumber</ejb-name>
              </relationship-role-source>
              <cmr-field>
              <cmr-field-name>employee</cmr-field-name>
              </cmr-field>
              </ejb-relationship-role>
              </ejb-relation>


              <assembly-descriptor>
              <container-transaction>

              <ejb-name>BmEmployee</ejb-name>
              <method-name>*</method-name>

              <trans-attribute>Required</trans-attribute>
              </container-transaction>
              <container-transaction>

              <ejb-name>BmEmployeeNumber</ejb-name>
              <method-name>*</method-name>

              <trans-attribute>Required</trans-attribute>
              </container-transaction>
              </assembly-descriptor>

              </ejb-jar>


              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>

              java:/MySqlDS
              <datasource-mapping>mySQL</datasource-mapping>

              <enterprise-beans>

              <ejb-name>BmEmployee</ejb-name>
              <table-name>Employees</table-name>
              <cmp-field>
              <field-name>empPk</field-name>
              <column-name>emp_pk</column-name>
              </cmp-field>
              <cmp-field>
              <field-name>firstName</field-name>
              <column-name>first_name</column-name>
              </cmp-field>
              <cmp-field>
              <field-name>lastName</field-name>
              <column-name>last_name</column-name>
              </cmp-field>


              <ejb-name>BmEmployeeNumber</ejb-name>
              <table-name>EmployeeNumbers</table-name>
              <cmp-field>
              <field-name>phonePk</field-name>
              <column-name>phone_pk</column-name>
              </cmp-field>
              <cmp-field>
              <field-name>phoneNumber</field-name>
              <column-name>phone_number</column-name>
              </cmp-field>

              </enterprise-beans>

              <ejb-relation>
              <ejb-relation-name>Employee-PhoneNumbers</ejb-relation-name>
              <foreign-key-mapping />
              <ejb-relationship-role>
              <ejb-relationship-role-name>BmEmployee-has-BmEmployeeNumbers</ejb-relationship-role-name>
              <key-fields>
              <key-field>
              <field-name>empPk</field-name>
              <column-name>emp_fk</column-name>
              </key-field>
              </key-fields>
              </ejb-relationship-role>
              <ejb-relationship-role>
              <ejb-relationship-role-name>BmEmployeeNumber-belongs-to-BmEmployee</ejb-relationship-role-name>
              <key-fields />
              </ejb-relationship-role>
              </ejb-relation>

              </jbosscmp-jdbc>

              BmEmployee create methods:

              public Integer ejbCreate(String firstName, String lastName) throws CreateException {
              setFirstName(firstName);
              setLastName(lastName);
              return null;
              }

              public void ejbPostCreate(String firstName, String lastName) {
              System.out.println("************ in ejbPostCreate *************");
              }

              BmEmployeeNumber create methods:

              public Integer ejbCreate(BmEmployeeLocal employee, String phoneNumber) throws CreateException {
              setPhoneNumber(phoneNumber);
              return null;
              }

              public void ejbPostCreate(BmEmployeeLocal employee, String phoneNumber) {
              System.out.println("**** in BmEmployeeNumberEJB ejbPostCreate() ****");
              setEmployee(employee);
              }

              • 4. Re: ejbPostCreate method is not being called, any ideas?
                dean_tanabe

                I have had the same results using version 3.0.1. I thought I'd post the ejb-jar.xml and jbosscmp-jdbc.xml files and the create methods for the beans in hopes that someone can tell me where my error is. I'm using JBoss version 3.0.2 and mysql 3.23.52

                EJB-JAR.XML

                <?xml version="1.0"?>
                <!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>
                <enterprise-beans>

                <ejb-name>BmEmployee</ejb-name>
                <local-home>bm.ejb.BmEmployeeLocalHome</local-home>
                bm.ejb.BmEmployeeLocal
                <ejb-class>bm.ejb.BmEmployeeEJB</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>BmEmployee</abstract-schema-name>
                <cmp-field><field-name>empPk</field-name></cmp-field>
                <cmp-field><field-name>firstName</field-name></cmp-field>
                <cmp-field><field-name>lastName</field-name></cmp-field>
                <primkey-field>empPk</primkey-field>
                <ejb-local-ref>
                <ejb-ref-name>ejb/BmEmployeeNumberLocal</ejb-ref-name>
                <ejb-ref-type>Entity</ejb-ref-type>
                <local-home>bm.ejb.BmEmployeeNumberLocalHome</local-home>
                bm.ejb.BmEmployeeNumberLocal
                <ejb-link>BmEmployeeNumber</ejb-link>
                </ejb-local-ref>


                <ejb-name>BmEmployeeNumber</ejb-name>
                <local-home>bm.ejb.BmEmployeeNumberLocalHome</local-home>
                bm.ejb.BmEmployeeNumberLocal
                <ejb-class>bm.ejb.BmEmployeeNumberEJB</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>BmEmployeeNumber</abstract-schema-name>
                <cmp-field><field-name>phonePk</field-name></cmp-field>
                <cmp-field><field-name>phoneNumber</field-name></cmp-field>
                <primkey-field>phonePk</primkey-field>

                </enterprise-beans>


                <ejb-relation>
                <ejb-relation-name>Employee-PhoneNumbers</ejb-relation-name>
                <ejb-relationship-role>
                <ejb-relationship-role-name>
                BmEmployee-has-BmEmployeeNumbers
                </ejb-relationship-role-name>
                One
                <relationship-role-source>
                <ejb-name>BmEmployee</ejb-name>
                </relationship-role-source>
                <cmr-field>
                <cmr-field-name>phoneNumbers</cmr-field-name>
                <cmr-field-type>java.util.Collection</cmr-field-type>
                </cmr-field>
                </ejb-relationship-role>
                <ejb-relationship-role>
                <ejb-relationship-role-name>
                BmEmployeeNumber-belongs-to-BmEmployee
                </ejb-relationship-role-name>
                Many
                <cascade-delete />
                <relationship-role-source>
                <ejb-name>BmEmployeeNumber</ejb-name>
                </relationship-role-source>
                <cmr-field>
                <cmr-field-name>employee</cmr-field-name>
                </cmr-field>
                </ejb-relationship-role>
                </ejb-relation>


                <assembly-descriptor>
                <container-transaction>

                <ejb-name>BmEmployee</ejb-name>
                <method-name>*</method-name>

                <trans-attribute>Required</trans-attribute>
                </container-transaction>
                <container-transaction>

                <ejb-name>BmEmployeeNumber</ejb-name>
                <method-name>*</method-name>

                <trans-attribute>Required</trans-attribute>
                </container-transaction>
                </assembly-descriptor>

                </ejb-jar>


                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>

                java:/MySqlDS
                <datasource-mapping>mySQL</datasource-mapping>

                <enterprise-beans>

                <ejb-name>BmEmployee</ejb-name>
                <table-name>Employees</table-name>
                <cmp-field>
                <field-name>empPk</field-name>
                <column-name>emp_pk</column-name>
                </cmp-field>
                <cmp-field>
                <field-name>firstName</field-name>
                <column-name>first_name</column-name>
                </cmp-field>
                <cmp-field>
                <field-name>lastName</field-name>
                <column-name>last_name</column-name>
                </cmp-field>


                <ejb-name>BmEmployeeNumber</ejb-name>
                <table-name>EmployeeNumbers</table-name>
                <cmp-field>
                <field-name>phonePk</field-name>
                <column-name>phone_pk</column-name>
                </cmp-field>
                <cmp-field>
                <field-name>phoneNumber</field-name>
                <column-name>phone_number</column-name>
                </cmp-field>

                </enterprise-beans>

                <ejb-relation>
                <ejb-relation-name>Employee-PhoneNumbers</ejb-relation-name>
                <foreign-key-mapping />
                <ejb-relationship-role>
                <ejb-relationship-role-name>BmEmployee-has-BmEmployeeNumbers</ejb-relationship-role-name>
                <key-fields>
                <key-field>
                <field-name>empPk</field-name>
                <column-name>emp_fk</column-name>
                </key-field>
                </key-fields>
                </ejb-relationship-role>
                <ejb-relationship-role>
                <ejb-relationship-role-name>BmEmployeeNumber-belongs-to-BmEmployee</ejb-relationship-role-name>
                <key-fields />
                </ejb-relationship-role>
                </ejb-relation>

                </jbosscmp-jdbc>

                BmEmployee create methods:

                public Integer ejbCreate(String firstName, String lastName) throws CreateException {
                setFirstName(firstName);
                setLastName(lastName);
                return null;
                }

                public void ejbPostCreate(String firstName, String lastName) {
                System.out.println("************ in ejbPostCreate *************");
                }

                BmEmployeeNumber create methods:

                public Integer ejbCreate(BmEmployeeLocal employee, String phoneNumber) throws CreateException {
                setPhoneNumber(phoneNumber);
                return null;
                }

                public void ejbPostCreate(BmEmployeeLocal employee, String phoneNumber) {
                System.out.println("**** in BmEmployeeNumberEJB ejbPostCreate() ****");
                setEmployee(employee);
                }

                • 5. Re: ejbPostCreate method is not being called, any ideas?
                  dean_tanabe

                  Sorry, if this message is posted a few times, I couldn't see the last 2 after posting. I've added the message content as an attachment. It includes the ejb-jar.xml, jbosscmp-jdbc.xml, and create methods that I'm using.

                  Much Aloha,
                  Dean

                  • 6. Re: ejbPostCreate method is not being called, any ideas?
                    dean_tanabe

                    I'm still having this problem with the latest JBoss release version. Wondering if anyone has any ideas to help? Much thanks..

                    Much Aloha,
                    Dean

                    • 7. Re: ejbPostCreate method is not being called, any ideas?
                      tdhak

                      I'm having exactly the same problem, and I haven't got a clue as to why it is happening.

                      I've just started looking at the JBoss source, to see what reasons the ejbPostCreate method wouldn't be called, but I haven't found anything yet.

                      Tarwinder Dhak

                      • 8. Re: ejbPostCreate method is not being called, any ideas?
                        tdhak

                        Hi,

                        OK I've solved my problem !!

                        I had a table in my database whos primary key was an auto incrementing integer. In my entity bean, the create method returned type Integer, although in the actual method I was not setting the ID cos I thought it would be automatically incremented.

                        When I looked in the database, everything seemed fine, the ID was indeed auto incrementing, however, what I failed to realise was that JBoss uses the primary key of an entity internaly to keep track of entities, hence the primary key can't be null.

                        So what was happening in effect was that when I created the entity bean, the ID of the bean was null, which meant that JBoss couldn't keep track of the object, therefore couldn't call the ejbPostCreate() method on it.

                        It might be an idea for the developers of JBoss to add a warning or error message when the primary key of an entity bean is null.

                        Hope this helps some people who are having a similar problem !!

                        Tarwinder Dhak

                        • 9. Re: ejbPostCreate method is not being called, any ideas?
                          dean_tanabe

                          Awesome.. thanks so much! I've got it working as well now.

                          Much Aloha,
                          Dean