6 Replies Latest reply on Mar 12, 2003 10:26 AM by dcs1pk

    Problem with CMR with auto-increment primary key in JBoss 3.

    bobo1025

      I am currently using JBoss 3.2RC1. I am able to get CMP to work with auto-increment primary key support in the 3.2 feature. However, to get auto-increment primary key to work in CMP, the primary key field cannot be declared in the ejb-jar.xml, nor the jbosscmp-jdbc.xml file. However, to setup CMR, the mapping requires a foreign key to be mapped to a cmp-field, in this case the auto-increment primary key. But the auto-increment primary key must not be declared in order to for CMP to work. Any one has any solution?

      The jbosscmp-jdbc.xml file content
      <jbosscmp-jdbc>

      java:/MSSQLDS
      <datasource-mapping>MS SQLSERVER</datasource-mapping>
      <create-table>false</create-table>
      <remove-table>false</remove-table>
      <enterprise-beans>

      <ejb-name>AddressEJB</ejb-name>
      <table-name>TAddress</table-name>
      <cmp-field>
      <field-name>street1</field-name>
      <column-name>Street1</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>street2</field-name>
      <column-name>Street2</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>city</field-name>
      <column-name>City</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>state</field-name>
      <column-name>State</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>postalCode</field-name>
      <column-name>PostalCode</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>country</field-name>
      <column-name>Country</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>lastUpdated</field-name>
      <column-name>LastUpdated</column-name>
      </cmp-field>
      <unknown-pk>
      <unknown-pk-class>java.lang.Integer</unknown-pk-class>
      <column-name>AddressId</column-name>
      <jdbc-type>INTEGER</jdbc-type>
      <sql-type>INTEGER</sql-type>
      </unknown-pk>
      <entity-command name="get-generated-keys"/>


      <ejb-name>UserInfoEJB</ejb-name>
      <table-name>TUserInfo</table-name>
      <cmp-field>
      <field-name>userInfoId</field-name>
      <column-name>UserInfoId</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>title</field-name>
      <column-name>Title</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>firstName</field-name>
      <column-name>FirstName</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>lastName</field-name>
      <column-name>LastName</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>personalPhoneNumber</field-name>
      <column-name>PersonalPhoneNumber</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>faxNumber</field-name>
      <column-name>FaxNumber</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>businessPhoneNumber</field-name>
      <column-name>BusinessPhoneNumber</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>joinDate</field-name>
      <column-name>JoinDate</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>notes</field-name>
      <column-name>Notes</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>lastUpdated</field-name>
      <column-name>LastUpdated</column-name>
      </cmp-field>
      <unknown-pk>
      <unknown-pk-class>java.lang.Integer</unknown-pk-class>
      <column-name>UserInfoId</column-name>
      <jdbc-type>INTEGER</jdbc-type>
      <sql-type>INTEGER</sql-type>
      </unknown-pk>
      <entity-command name="get-generated-keys"/>

      </enterprise-beans>

      <ejb-relation>
      <ejb-relation-name>UserInfo-Address</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>userinfo-has-an-address</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>address</field-name>
      <column-name>AddressId</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>address-assignedTo-userinfo</ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      </ejb-relation>

      </jbosscmp-jdbc>

        • 1. Mysql int auto increment  as primary key
          sood_brijesh

          hi please check the file attached contain sa simple test entity bean using mysql int auto increment key as primary key
          but to use this features u need to have mysql-connector-java-3.0.1-beta driver u can down from this site http://mysql.azc.uam.mx/Downloads/Connector-J/

          • 2. Re: Problem with CMR with auto-increment primary key in JBos
            sood_brijesh

            Hi please check this attached code this have 4 entity bean attached and the primary key field are db based auto number pand all the entity beans are linked through it (acting as the cmr field). and one staleless session ejb managing the relationship with these beans ..

            • 3. Re: Problem with CMR with auto-increment primary key in JBos
              sood_brijesh

               

              "sood_brijesh" wrote:
              Hi please check this attached code, Having 4 entity beans
              CustomerEJB , AddressEJB , PhoneEJB , & CreditCard ..
              and all are using id as the primary key field name and it is mysql db based auto number field. there is undirection relationship mapping from CustomerEJB to AddressEJB (one to one ) and Customer to PhoneEJB( one to many unidirectional) and Customer to CreditCard (bidirectional one to one) the id is autonumber field name not mentioned in the deployement descirptor as the cmp field instead mention it in the jbosscmp-jdbc.xml ..
              & all of ur relationship type has to bee defined in the ejb-jar.xml file .. i have tried all this code jboss3.2.03 beta with jconnector 3.01 beta driver ..and its working fine ..



              • 4. Re: Problem with CMR with auto-increment primary key in JBos
                sood_brijesh

                Hi please check this attached code, Having 4 entity beans
                CustomerEJB , AddressEJB , PhoneEJB , & CreditCard ..
                and all are using id as the primary key field name and it is mysql db based auto number field. there is undirection relationship mapping from CustomerEJB to AddressEJB (one to one ) and Customer to PhoneEJB( one to many unidirectional) and Customer to CreditCard (bidirectional one to one) the id is autonumber field name not mentioned in the deployement descirptor as the cmp field instead mention it in the jbosscmp-jdbc.xml ..
                & all of ur relationship type has to bee defined in the ejb-jar.xml file .. i have tried all this code jboss3.2.03 beta with jconnector 3.01 beta driver ..and its working fine ..

                • 5. Re: Problem with CMR with auto-increment primary key in JBos
                  crowley

                  Hi! Where have you defined the key fields for the relationships? It's not in the jbosscmp-jdbc.xml...

                  • 6. Re: Problem with CMR with auto-increment primary key in JBos
                    dcs1pk

                    Hi, I am having the exactly same problem. How do I define cmp field name from unknown-pk???? This is needed by CMR for reference.

                    Ive try to put

                    <unknown-pk>
                    ..
                    ..
                    <field-name>Id</field-name>

                    </unknown-pk>

                    But it doesnt work!!!!!!!!!

                    Please Help!