3 Replies Latest reply on Mar 15, 2006 11:30 AM by antgod

    Weblogic to JBoss EJB-CMP doesnt work

    antgod

      Hi,

      I am trying to deploy and existing web application from Weblogic to JBoss. I am now able to successfully deploy and run the main application, however when I try to do a save function, I get errors like this:


      15:24:33,806 ERROR [AuftragDO] Could not create entity
      java.sql.SQLException: ORA-01400: cannot insert NULL into ("KSO_ANTGODE"."T_EC_AUFTRAG"."EKU_ID")
      ORA-06512: at line 1
      
       at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
       at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
       at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
       at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
       at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:215)
       at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:954)
       at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1168)
       at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
       at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3390)
       at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4223)
       at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.execute(WrappedPreparedStatement.java:183)
       at org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCOracleCreateCommand.executeInsert(JDBCOracleCreateCommand.java:83)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.performInsert(JDBCAbstractCreateCommand.java:308)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.execute(JDBCAbstractCreateCommand.java:138)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:572)
       at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:222)
       at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:219)
       at org.jboss.ejb.EntityContainer.createLocalHome(EntityContainer.java:612)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)


      I have searched and tried possible solutions, either in the deployment descriptor or in the code, but of no luck.

      I am wondering if this has to do with the CMP/CMR fields I am using, in the above error, I always get a null for the foreign key - EKU_ID and it states that I cannot insert NULL.

      Any idea how can I solve this?

      Attached also is my ejb-jar.xml and jbosscmp-jdbc.xml..

      ejb-jar.xml

      <?xml version="1.0"?>
      <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd'>
      <ejb-jar>
       <entity>
       <ejb-name>KundeDo</ejb-name>
       <local-home>de.dbsystems.spi.kso.dbo.kunde.KundeDoLocalHome</local-home>
       <local>de.dbsystems.spi.kso.dbo.kunde.KundeDoLocal</local>
       <ejb-class>de.dbsystems.spi.kso.dbo.kunde.KundeDoEB</ejb-class>
       <persistence-type>Container</persistence-type>
       <prim-key-class>java.lang.Long</prim-key-class>
       <reentrant>False</reentrant>
       <cmp-version>2.x</cmp-version>
       <abstract-schema-name>KundeDo</abstract-schema-name>
       <cmp-field>
       <field-name>id</field-name>
       </cmp-field>
       <cmp-field>
       <field-name>eDIPasswort</field-name>
       </cmp-field>
       <cmp-field>
       <field-name>eDIProvider</field-name>
       </cmp-field>
       <cmp-field>
       <field-name>eingangsbestaetigung</field-name>
       </cmp-field>
       <cmp-field>
       <field-name>partnerBvwNr</field-name>
       </cmp-field>
       <cmp-field>
       <field-name>partnerId</field-name>
       </cmp-field>
       <cmp-field>
       <field-name>partnerStandort</field-name>
       </cmp-field>
       <cmp-field>
       <field-name>user</field-name>
       </cmp-field>
       <cmp-field>
       <field-name>timestamp</field-name>
       </cmp-field>
       <primkey-field>id</primkey-field>
       <query>
       <query-method>
       <method-name>findAllKunden</method-name>
       <method-params></method-params>
       </query-method>
       <ejb-ql>
       <![CDATA[SELECT OBJECT(obj) FROM KundeDo AS obj]]>
       </ejb-ql>
       </query>
       <query>
       <query-method>
       <method-name>findByStandortname</method-name>
       <method-params>
       <method-param>java.lang.String</method-param>
       </method-params>
       </query-method>
       <ejb-ql>
       <![CDATA[SELECT OBJECT(obj) FROM KundeDo AS obj WHERE obj.partnerStandort LIKE ?1]]>
       </ejb-ql>
       </query>
       <query>
       <query-method>
       <method-name>findByStandortnummer</method-name>
       <method-params>
       <method-param>java.lang.String</method-param>
       </method-params>
       </query-method>
       <ejb-ql>
       <![CDATA[SELECT OBJECT(obj) FROM KundeDo AS obj WHERE obj.partnerId LIKE ?1]]>
       </ejb-ql>
       </query>
       <query>
       <query-method>
       <method-name>findByEdiProvider</method-name>
       <method-params>
       <method-param>java.lang.String</method-param>
       </method-params>
       </query-method>
       <ejb-ql>
       <![CDATA[SELECT OBJECT(obj) FROM KundeDo AS obj WHERE obj.eDIProvider LIKE ?1]]>
       </ejb-ql>
       </query>
       </entity>
       <entity>
       <ejb-name>AuftragDO</ejb-name>
       <local-home>de.dbsystems.spi.kso.dbo.auftrag.AuftragDOLocalHome</local-home>
       <local>de.dbsystems.spi.kso.dbo.auftrag.AuftragDOLocal</local>
       <ejb-class>de.dbsystems.spi.kso.dbo.auftrag.AuftragDOEB</ejb-class>
       <persistence-type>Container</persistence-type>
       <prim-key-class>java.lang.Long</prim-key-class>
       <reentrant>False</reentrant>
       <cmp-version>2.x</cmp-version>
       <abstract-schema-name>AuftragDO</abstract-schema-name>
       <cmp-field>
       <field-name>id</field-name>
       </cmp-field>
       . . . . . .
       . . . . . .
       <cmp-field>
       <field-name>user</field-name>
       </cmp-field>
       <cmp-field>
       <field-name>timestamp</field-name>
       </cmp-field>
       <primkey-field>id</primkey-field>
       </entity>
       <relationships>
       <assembly-descriptor>
       <ejb-relation>
       <ejb-relation-name>kunde-user</ejb-relation-name>
       <ejb-relationship-role>
       <ejb-relationship-role-name>UserDo.kunde</ejb-relationship-role-name>
       <multiplicity>Many</multiplicity>
       <relationship-role-source>
       <ejb-name>UserDo</ejb-name>
       </relationship-role-source>
       <cmr-field>
       <cmr-field-name>kunde</cmr-field-name>
       </cmr-field>
       </ejb-relationship-role>
       <ejb-relationship-role>
       <ejb-relationship-role-name>KundeDo.users</ejb-relationship-role-name>
       <multiplicity>One</multiplicity>
       <relationship-role-source>
       <ejb-name>KundeDo</ejb-name>
       </relationship-role-source>
       <cmr-field>
       <cmr-field-name>users</cmr-field-name>
       <cmr-field-type>java.util.Collection</cmr-field-type>
       </cmr-field>
       </ejb-relationship-role>
       </ejb-relation>
       <ejb-relation>
       <ejb-relation-name>kunde-auftraege</ejb-relation-name>
       <ejb-relationship-role>
       <ejb-relationship-role-name>AuftragDO.kunde</ejb-relationship-role-name>
       <multiplicity>Many</multiplicity>
       <relationship-role-source>
       <ejb-name>AuftragDO</ejb-name>
       </relationship-role-source>
       <cmr-field>
       <cmr-field-name>kunde</cmr-field-name>
       </cmr-field>
       </ejb-relationship-role>
       <ejb-relationship-role>
       <ejb-relationship-role-name>KundeDo.auftraege</ejb-relationship-role-name>
       <multiplicity>One</multiplicity>
       <relationship-role-source>
       <ejb-name>KundeDo</ejb-name>
       </relationship-role-source>
       <cmr-field>
       <cmr-field-name>auftraege</cmr-field-name>
       <cmr-field-type>java.util.Collection</cmr-field-type>
       </cmr-field>
       </ejb-relationship-role>
       </ejb-relation>
       <container-transaction>
       <method>
       <ejb-name>KundeDo</ejb-name>
       <method-name>*</method-name>
       </method>
       <method>
       <ejb-name>AuftragsvorlageDO</ejb-name>
       <method-name>*</method-name>
       </method>
       <method>
       <ejb-name>AuftragDO</ejb-name>
       <method-name>*</method-name>
       </method>
       </container-transaction>
       </assembly-descriptor>
      </ejb-jar>



      this is my jbosscmp-jdbc.xml

      <?xml version="1.0"?>
      <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 4.0//EN"
       "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_4_0.dtd">
      <jbosscmp-jdbc>
       <defaults>
       <!-- <datasource>jdbc.kso.MainTxDatasource</datasource> -->
       <datasource>java:/XAOracleDS</datasource>
       <datasource-mapping>Oracle9i</datasource-mapping>
       <create-table>false</create-table>
       <alter-table>false</alter-table>
       <remove-table>false</remove-table>
       <read-only>false</read-only>
       </defaults>
       <enterprise-beans>
       <entity>
       <ejb-name>KundeDo</ejb-name>
       <table-name>T_EC_KUNDE</table-name>
       <cmp-field>
       <field-name>id</field-name>
       <column-name>EKU_ID</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>eDIPasswort</field-name>
       <column-name>EKU_EDI_PASSWORT</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>eDIProvider</field-name>
       <column-name>EKU_EDI_PROVIDER</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>eingangsbestaetigung</field-name>
       <column-name>EKU_ECBEST_CD</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>partnerBvwNr</field-name>
       <column-name>EKU_PTN_BVW_NR</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>partnerId</field-name>
       <column-name>EKU_PTN_ID</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>partnerStandort</field-name>
       <column-name>EKU_PTN_BEZEICHNUNG</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>user</field-name>
       <column-name>EKU_USER_ID</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>timestamp</field-name>
       <column-name>EKU_TIMESTAMP</column-name>
       </cmp-field>
       <unknown-pk>
       <unknown-pk-class>java.lang.Long</unknown-pk-class>
       <field-name>id</field-name>
       <column-name>EKU_ID</column-name>
       <jdbc-type>BIGINT</jdbc-type>
       <sql-type>NUMBER(19)</sql-type>
       <auto-increment/>
       </unknown-pk>
       <entity-command name="oracle-sequence" class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCOracleCreateCommand">
       <attribute name="sequence">S_EC_KUNDE</attribute>
       </entity-command>
       <optimistic-locking>
       <modified-strategy/>
       </optimistic-locking>
       </entity>
       <entity>
       <ejb-name>AuftragDO</ejb-name>
       <table-name>T_EC_AUFTRAG</table-name>
       <cmp-field>
       <field-name>id</field-name>
       <column-name>AFT_ID</column-name>
       </cmp-field>
       . . . . . .
       . . . . . .
       <cmp-field>
       <field-name>user</field-name>
       <column-name>AFT_USER_ID</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>timestamp</field-name>
       <column-name>AFT_TIMESTAMP</column-name>
       </cmp-field>
       <unknown-pk>
       <unknown-pk-class>java.lang.Long</unknown-pk-class>
       <field-name>id</field-name>
       <column-name>AFT_ID</column-name>
       <jdbc-type>BIGINT</jdbc-type>
       <sql-type>NUMBER(19)</sql-type>
       <auto-increment/>
       </unknown-pk>
       <entity-command name="oracle-sequence" class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCOracleCreateCommand">
       <attribute name="sequence">S_EC_AUFTRAG</attribute>
       </entity-command>
       <optimistic-locking>
       <modified-strategy/>
       </optimistic-locking>
       </entity>
       </enterprise-beans>
       <relationships>
       <ejb-relation>
       <ejb-relation-name>kunde-auftraege</ejb-relation-name>
       <foreign-key-mapping/>
       <ejb-relationship-role>
       <ejb-relationship-role-name>AuftragDO.kunde</ejb-relationship-role-name>
       </ejb-relationship-role>
       <ejb-relationship-role>
       <ejb-relationship-role-name>KundeDo.auftraege</ejb-relationship-role-name>
       <key-fields>
       <key-field>
       <field-name>id</field-name>
       <column-name>EKU_ID</column-name>
       </key-field>
       </key-fields>
       </ejb-relationship-role>
       </ejb-relation>
       </relationships>
      </jbosscmp-jdbc>



      I am wondering if I missed out on anything during the migration or I did something incorrect.

      Any help will be highly appreciated!

      AntGod

        • 1. Re: Weblogic to JBoss EJB-CMP doesnt work
          pdog4x4

          AntGod,

          I had this problem also with Oracle. Mine was caused by not creating my entity beans with the primary keys prior to updating the rest of the fields in the ejbCreate method. I create mine like this:

           /**
           * Create method
           * @ejb.create-method view-type = "local"
           */
           public infrastructure.interfaces.PersonPK ejbCreate(PersonData data)
           throws javax.ejb.CreateException {
          
           // Primary keys get set first!
           this.setEmail(data.getEmail());
          
           this.setFirstname(data.getFirstname());
           this.setLastname(data.getLastname());
           this.setPassword(data.getPassword());
           this.setUsername(data.getUsername());
          
           return null;
           }
          


          Or for my composite keys:
           /**
           * Create method
           * @ejb.create-method view-type = "local"
           */
           public infrastructure.interfaces.RouterUpdatePK ejbCreate(
           RouterUpdateData data) throws javax.ejb.CreateException {
          
           // Primary keys get set first!
           this.setModified_date(new Date());
           this.setSortingOrder(data.getSortingOrder());
          
           this.setCu_code(data.getCu_code());
           this.setCu_modified_date(data.getCu_modified_date());
           this.setPerson_email(data.getPerson_email());
           this.setConfiguration_code(data.getConfiguration_code());
           this.setPushStatus(data.getPushStatus());
           this.setRouter_pri_address(data.getRouter_pri_address());
           this.setRouter_priority(data.getRouter_priority());
          
           return null;
           }
          


          Maybe that helps?

          Thanks!

          Joshua Preston.

          • 2. Re: Weblogic to JBoss EJB-CMP doesnt work
            antgod

            I think I solve this, pelase see details of what I did...

            Investigations:
            Initial investigation suggests that the cause of the error is either of the following:
            1. The passed foreign key is null. In this case, EKU_ID is said to be null.
            - Immediate resolution is to trace through the code to check if the EKU_id field contains value. It was found out the the object has the EKU value
            2. There could be missing JBOSS configurations such as in the standardjbosscmp-jdbc.xml
            - extended logging facility to check where exact error occurs
            3. There could be missing tag elements in the descriptor files: JBOSSCMP-JDBC.xml, EJB-JAR.xml, JBOSS.xml
            a. JBOSSCMP-JDBC.xml:
            - checked "org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCOracleCreateCommand" for creation of sequence
            - checked usage of optimistic-locking since there is a table relationship
            - checked usage of <ejb-relation>, might have missed JBOSS-required element tag
            - checked usage of <cmp-field>
            b. EJB-JAR.xml
            - checked usage of <resource-ref>
            - usage of fields
            c. JBOSS.xml
            - added <insert-after-ejb-post-create>true</insert-after-ejb-post-create> since initially, ejbPostCreate() is not called in the code. The ejbPostCreate() should handle setting of CMR fields
            - added use of resource managers
            4. Checking code implementation of setting the CMP and CMR fields
            - the CMP fields should be set in the ejbCreate() methods and the CMR fields (eg setKunde()) should be set in the ejbPostCreate()
            - tried moving the CMR calls inside the ejbCreate() methods causes a TransactionRollbackException()
            5. Understanding how the container manages insertion of data, the insert SQL script is automatically generated after the ejbCreate() method


            Resolution:
            1. Creating a simple application with two tables (with relationships) deployed and runnable in JBOSS. The sample application however does not use foreign key constraints
            2. Tried removing the foreign key constraints from the KSO database/schema (eg. EKU_ID).
            3. Checked Frankfurt schema (SD12) and found out that there are no foreign key constraints implemented (see attached image)
            4. Tried setting the foreign key constraints as "Nullable". Currently, is it set to "Not Nullable"
            5. Furthermore, checking the JBOSS CMP 2 documentation (attached page 85-86) it was stated that all foreign key fields must ALWAYS be set to nullable.


            My question now, if it is really confirmed that foreign fields should always be nullable?

            • 3. Re: Weblogic to JBoss EJB-CMP doesnt work
              antgod

              By the way, thanks Joshua.

              The thing is, since we are only doing migration of the current codes from Weblogic to JBoss, we are required to as much as possible minimize code changes. I had that in mind (your suggestion), but that would require a change in the existing codes.

              Nevertheless, again I appreciate your thoughts!