I use Hibernate and mySql.
I have defined the db script as follows:
CREATE TABLE `Foo` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`version` int(11) NOT NULL DEFAULT '0',
`data` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`)
);
ALTER TABLE Foo AUTO_INCREMENT = 34324;
and this is my hibernate mapping:
<class name="org.xyz.Foo" table="Foo">
<cache usage="read-write"/>
<id name="id" column="id">
<generator class="increment"/>
</id>
<version name="version" column="version"/>
<property name="data" column="data"/>
</class>
Problem : The inserts are not respecting the AutoIncrement Id which is set as 34324. The inserted Ids start from 1 instead of 34324 as I expected.
I am not setting Ids myself.
According your hibernate mapping preferred generation strategy is
increment. This means that Hibernate generates value. But according DDL column should be AUTO_INCREMENT, which means value is assigned by MySQL.If AUTO_INCREMENT is what you want, solution is to use following Hibernate mapping: