2

I have a MySQL table naming Invoice for a Inventory Monitoring site, invoice_number is bigint(19) AUTO_INCREMENT field.

Currently AUTO_INCREMENT value is 1.

Client want it to start the invoice_number from 50000. With the following script reset the ALTER TABLE INVOICES AUTO_INCREMENT = 50000; When I wrote an Insert Script to insert data in SQLDBX, it is putting the invoice_number from 50000. But when i am trying to do insert a record using the application(web application), the invoice_number value is starting from 1. We are making use of Spring-JDBC template to insert data into mysql database.

Sai Srikanth
  • 85
  • 1
  • 8
  • That doesn't make sense. There is something else going on, like different tables, or databases, or the web app is creating its own increments. – Ariel Sep 06 '12 at 01:34

1 Answers1

2

The issue is with the Hibernate HBM mapping for Invoice. The generator class for Invoice Number is Increment.

<id name="invoiceNumber" column="INVOICE_NUMBER">
   <generator class="increment"/>
</id>

By modifying the generator class to identity it worked.

<id name="invoiceNumber" column="INVOICE_NUMBER">
    <generator class="identity"/>
</id>

For more detailed information, please check Hibernate problems with Auto Increment ID MYSQL 5 Also check this Hibernate not respecting MySQL auto_increment primary key field

Community
  • 1
  • 1
Sai Srikanth
  • 85
  • 1
  • 8