I am working on a database application which is mostly read-only, but there is one table which records user movement in the app and has a large number of writes to it. For
Increment is definitely bad if you have more than one process writing to the same table - you're bound to have collisions.
Since it is MySQL we're talking about, the easiest thing to use would be identity
. In your Hibernate mapping:
<generator class="identity"/>
In your MySQL script:
CREATE TABLE IF NOT EXISTS `my_table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`data1` int(11) NOT NULL,
`data2` int(11) NOT NULL,
`timestamp` datetime default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
To alter an existing table:
ALTER TABLE `my_table`
CHANGE COLUMN `id` `id` int(11) NOT NULL AUTO_INCREMENT=$NEW_VALUE$;
where $NEW_VALUE$ should be replaced by the next available id so that sequence does not reset to 1.