5 Replies Latest reply on May 23, 2002 10:25 AM by Prabha

    Duplicate column error

    Prabha Newbie

      Hi,

      I am using jboss3.0 beta version. I have 2 entity beans in a container. I am trying to implement 1-1 relationship (unidirectional). The two entities are KMF and Key. Without specifying any relationship, I am able to create/read from the database (Oracle 8.1.7). The minute I specify any relationship, I start to see errors. I see duplicate column error.

      The following is in the ejb-jar.xml:
      "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
      <ejb-jar>
      ![CDATA[This is a JEE test using JBoss 3.0 CMP/CTM.]]
      <display-name>JEE/JBOSS TEST</display-name>
      <enterprise-beans>

      <![CDATA[KMFSessionBean.]]>
      <display-name>KMFSessionBean</display-name>
      <ejb-name>KMFSession</ejb-name>
      ejb.KMFSessionHome
      ejb.KMFSession
      <ejb-class>ejb.KMFSessionBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
      <resource-ref>
      <res-ref-name>OracleDS</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>


      <![CDATA[KMFBean.]]>
      <display-name>KMF</display-name>
      <ejb-name>KMF</ejb-name>
      ejb.KMFHome
      ejb.KMF
      <local-home>ejb.KMFLocalHome</local-home>
      ejb.KMFLocal
      <ejb-class>ejb.KMFBean</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>KMF</abstract-schema-name>
      <cmp-field><field-name>kmfId</field-name></cmp-field>
      <cmp-field><field-name>name</field-name></cmp-field>
      <primkey-field>kmfId</primkey-field>

      finder -> Find all KMFBeans
      <query-method>
      <method-name>findAll</method-name>
      <method-params></method-params>
      </query-method>
      <ejb-ql>
      SELECT OBJECT(p)
      FROM KMF p
      </ejb-ql>


      ejbSelect -> Find all KMFBeans
      <query-method>
      <method-name>ejbSelectIds</method-name>
      <method-params></method-params>
      </query-method>
      <ejb-ql>
      SELECT OBJECT(p)
      FROM KMF p
      </ejb-ql>


      <query-method>
      <method-name>findByName</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <ejb-ql>
      <!-- This is overriden in jbosscmp-jdbc.xml file -->
      </ejb-ql>

      <transaction-type>Container</transaction-type>
      <env-entry>
      <env-entry-name>DataSource</env-entry-name>
      <env-entry-type>java.lang.String</env-entry-type>
      <env-entry-value>OracleDS</env-entry-value>
      </env-entry>
      <resource-ref>
      <res-ref-name>jdbc/OracleDS</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>


      <![CDATA[KMFBean.]]>
      <display-name>Key</display-name>
      <ejb-name>Key</ejb-name>
      ejb.KeyHome
      ejb.Key
      <local-home>ejb.KeyLocalHome</local-home>
      ejb.KeyLocal
      <ejb-class>ejb.KeyBean</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>Key</abstract-schema-name>
      <cmp-field><field-name>keyId</field-name></cmp-field>
      <cmp-field><field-name>name</field-name></cmp-field>
      <primkey-field>keyId</primkey-field>

      finder -> Find all KeyBeans
      <query-method>
      <method-name>findAll</method-name>
      <method-params></method-params>
      </query-method>
      <ejb-ql>
      SELECT OBJECT(p)
      FROM Key p
      </ejb-ql>


      ejbSelect -> Find all KeyBeans
      <query-method>
      <method-name>ejbSelectIds</method-name>
      <method-params></method-params>
      </query-method>
      <ejb-ql>
      SELECT OBJECT(p)
      FROM Key p
      </ejb-ql>


      <query-method>
      <method-name>findByName</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <ejb-ql>
      <!-- This is overriden in jbosscmp-jdbc.xml file -->
      </ejb-ql>

      <transaction-type>Container</transaction-type>
      <env-entry>
      <env-entry-name>DataSource</env-entry-name>
      <env-entry-type>java.lang.String</env-entry-type>
      <env-entry-value>OracleDS</env-entry-value>
      </env-entry>
      <resource-ref>
      <res-ref-name>jdbc/OracleDS</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>

      </enterprise-beans>

      <ejb-relation>
      <ejb-relation-name>KMF-Key</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>KMFhasKey</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>KMF</ejb-name>
      <cmr-field>
      <cmr-field-name>myKey</cmr-field-name>
      </cmr-field>
      </relationship-role-source>
      </ejb-relationship-role>

      <ejb-relationship-role>
      <ejb-relationship-role-name>KeyhasKMF</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>KMF</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>

      </ejb-relation>



      <assembly-descriptor>
      <container-transaction>

      <ejb-name>KMFSession</ejb-name>
      <method-intf>Remote</method-intf>
      <method-name>*</method-name>

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

      <ejb-name>KMF</ejb-name>
      <method-intf>Remote</method-intf>
      <method-name>*</method-name>


      <ejb-name>KMF</ejb-name>
      <method-intf>Home</method-intf>
      <method-name>*</method-name>

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

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

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

      <ejb-name>Key</ejb-name>
      <method-intf>Remote</method-intf>
      <method-name>*</method-name>


      <ejb-name>Key</ejb-name>
      <method-intf>Home</method-intf>
      <method-name>*</method-name>

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

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

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <security-role>
      Users
      <role-name>users</role-name>
      </security-role>
      </assembly-descriptor>
      </ejb-jar>



      The following is in jbosscmp-jdbc.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <jbosscmp-jdbc>


      java:/OracleDS
      <type-mapping>Oracle8</type-mapping>
      true
      <create-table>false</create-table>
      <remove-table>false</remove-table>
      <read-only>false</read-only>
      <time-out>300</time-out>
      <select-for-update>false</select-for-update>
      <pk-constraint>true</pk-constraint>
      <relation-mapping-style>foreign-key</relation-mapping-style>


      <enterprise-beans>


      <ejb-name>KMF</ejb-name>
      <table-name>KMF</table-name>
      true
      <cmp-field>
      <field-name>kmfId</field-name>
      <column-name>ID</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR2(50)</sql-type>
      </cmp-field>
      <cmp-field>
      <field-name>name</field-name>
      <column-name>name</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR2(128)</sql-type>
      </cmp-field>

      <query-method>
      <method-name>findByName</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <declared-sql>
      name={0}
      </declared-sql>




      <ejb-name>Key</ejb-name>
      <table-name>Key</table-name>
      true
      <cmp-field>
      <field-name>keyId</field-name>
      <column-name>ID</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR2(50)</sql-type>
      </cmp-field>
      <cmp-field>
      <field-name>name</field-name>
      <column-name>name</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR2(128)</sql-type>
      </cmp-field>

      <query-method>
      <method-name>findByName</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <declared-sql>
      name={0}
      </declared-sql>



      </enterprise-beans>


      <ejb-relation>
      <ejb-relation-name>KMF-Key</ejb-relation-name>
      <foreign-key-mapping>
      <entity-relationship-role>
      <ejb-relationship-role-name>KMFhasKey</ejb-relationship-role-name>
      <foreign-key-fields>
      <foreign-key-field>
      </foreign-key-field>
      <field-name>KeyId</field-name>
      <column-name>PART_ID</column-name>
      </foreign-key-fields>
      </entity-relationship-role>

      <entity-relationship-role>
      <ejb-relationship-role-name>KeyhasKMF</ejb-relationship-role-name>
      <foreign-key-fields/>
      </entity-relationship-role>

      </foreign-key-mapping>

      </ejb-relation>



      </jbosscmp-jdbc>

      The tables I have:
      Table: KMF
      Name Null? Type
      ---------------------- -------- ------------------
      ID NOT NULL VARCHAR2(50)
      NAME VARCHAR2(150)
      PART_ID VARCHAR2(50)

      table name: Key
      Name Null? Type
      ---------------------- -------- -------------
      ID NOT NULL VARCHAR2(50)
      NAME VARCHAR2(200)

      This is the error I see:

      javax.ejb.CreateException: Could not create entity:java.sql.SQLException: ORA-00957: duplicate column name


      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:245)

      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:220)

      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)

      at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)

      at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:174)

      at org.jboss.proxy.ejb.GenericProxy.invoke(GenericProxy.java:182)

      at org.jboss.proxy.ejb.StatelessSessionProxy.invoke(StatelessSessionProxy.java:111)


      Has anyone seen this? Or am I doing something wrong? I will appreciate any help.

      Thanks,
      Prabha.

        • 1. Re: Duplicate column error
          Prabha Newbie

          That was hard to read. Sorry about it. This is the section I am concerned about in ejb-jar.xml, there was a typo (in bold) I fixed it, and I see invalid column name error:


          <ejb-relation>
          <ejb-relation-name>KMF-Key</ejb-relation-name>
          <ejb-relationship-role>
          <ejb-relationship-role-name>KMFhasKey</ejb-relationship-role-name>
          One
          <relationship-role-source>
          <ejb-name>KMF</ejb-name>
          <cmr-field>
          <cmr-field-name>myKey</cmr-field-name>
          </cmr-field>
          </relationship-role-source>
          </ejb-relationship-role>

          <ejb-relationship-role>
          <ejb-relationship-role-name>KeyhasKMF</ejb-relationship-role-name>
          One
          <relationship-role-source>
          <ejb-name>Key</ejb-name>
          </relationship-role-source>
          </ejb-relationship-role>

          </ejb-relation>



          In jbosscmp-jdbc.xml:


          <ejb-relation>
          <ejb-relation-name>KMF-Key</ejb-relation-name>
          <foreign-key-mapping>
          <entity-relationship-role>
          <ejb-relationship-role-name>KMFhasKey</ejb-relationship-role-name>
          <foreign-key-fields>
          <foreign-key-field>
          </foreign-key-field>
          <field-name>KeyId</field-name>
          <column-name>PART_ID</column-name>
          </foreign-key-fields>
          </entity-relationship-role>

          <entity-relationship-role>
          <ejb-relationship-role-name>KeyhasKMF</ejb-relationship-role-name>
          <foreign-key-fields/>
          </entity-relationship-role>

          </foreign-key-mapping>

          </ejb-relation>



          Thanks,
          Prabha.

          • 2. Re: Duplicate column error
            Dain Sundstrom Master

            Upgrade to JBoss 3.0 RC1

            • 3. Re: Duplicate column error(Now invalid column name error)
              Prabha Newbie

              Hi,

              I upgraded to JBoss 3.0 RC1, I am still seeing the invalid column name error. The generated sql is:

              2002-04-19 14:03:29,372 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.KMF] Executing SQL: INSERT INTO KMF (ID, name, Key_null) VALUES (?, ?, ?)


              Where is "Key_null" obtained from? There is no key_null in my table. Also, the column I mapped the foreign key in jbosscmp-jdbc.xml is PART_ID.

              Has anyone seen this before?

              Thanks,
              Prabha.

              • 4. Re: Duplicate column error(Now invalid column name error)
                Dain Sundstrom Master

                Is jbosscmp-jdbc.xml file still in the old format? If so check out the new dtd; it is documented.

                • 5. Re: Duplicate column error(Now invalid column name error)
                  Prabha Newbie

                  Where do I get the latest dtd from? Is there any examples where I can see how 1-1, 1-m relations are handled using CMP, Jboss RC1?