3 Replies Latest reply on Nov 12, 2004 4:01 AM by aloubyansky

    auto-increment problem

    joerage

      Hi, i am using JBoss with SQL Server.
      I am trying to use the auto increment feature, but I cannot make it work.

      Here is my bean:

       /**
       * Return the user id.
       * @return the userId
       * @ejb.persistent-field
       * @ejb.interface-method
       * @jboss.persistence
       * auto-increment="true"
       */
       public abstract String getId();
       /**
       * Set the user id.
       * @ejb.interface-method
       */
       public abstract void setId(String id);
      


      And here is my jbosscmp-jdbc.xml

      <ejb-name>UserDetail</ejb-name>
      
       <cmp-field>
       <field-name>id</field-name>
      
       <auto-increment/>
       </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>


      Here is the error i get:

      12:04:30,640 ERROR [UserDetail] Could not create entity
      java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot insert the value NULL into column 'id', table 'JoeTest.dbo.UserDetail'; column does not allow nulls. INSERT fails.


      Do you know my error?

        • 1. Re: auto-increment problem
          aloubyansky

          Yes, you should also use key generating entity-command. See standardjbosscmp-jdbc.xml.

          • 2. Re: auto-increment problem
            joerage

            Thanks for your answer.

            I changed my standardjbosscmp-jdbc.xml as follows:

            <defaults>
             <datasource>java:/MSSQLDS</datasource>
             <!-- optional since 4.0 <datasource-mapping>Hypersonic SQL</datasource-mapping> -->
            
             <create-table>true</create-table>
             <remove-table>false</remove-table>
             <read-only>false</read-only>
             <read-time-out>300000</read-time-out>
             <row-locking>false</row-locking>
             <pk-constraint>true</pk-constraint>
             <fk-constraint>true</fk-constraint>
             <preferred-relation-mapping>foreign-key</preferred-relation-mapping>
             <read-ahead>
             <strategy>on-load</strategy>
             <page-size>1000</page-size>
             <eager-load-group>*</eager-load-group>
             </read-ahead>
             <list-cache-max>1000</list-cache-max>
             <clean-read-ahead-on-load>false</clean-read-ahead-on-load>
            
             <unknown-pk>
             <key-generator-factory>UUIDKeyGeneratorFactory</key-generator-factory>
             <unknown-pk-class>java.lang.Integer</unknown-pk-class>
             <jdbc-type>INTEGER</jdbc-type>
             <sql-type>INTEGER</sql-type>
             </unknown-pk>
            
             <entity-command name="mssql-fetch-key" class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCSQLServerCreateCommand"/>
             <ql-compiler>org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLCompiler</ql-compiler>
             </defaults>


            I still get the same error.

            Any ideas?
            Or if somebody has working code, it would be very helpful.

            Thanks
            Joe

            • 3. Re: auto-increment problem
              aloubyansky

              Not in standardjbosscmp-jdbc.xml but in jbosscmp-jdbc.xml in the entity element.