All, This may be more of a hibernate/MySql issue than an Appfuse one but this could occur is Appfuse as well. I am trying to generate Ids for newly added customers using a table called SEQUENCE in MySql 5.0. I am using hibernate 3.2.1.ga annotations. The next customer I enter should have an Id of 101 since the SEQ_GEN from my SEQUENCE table is currently set to 100. For some reason I think MySql is generation a different value because the customer is assigned an Id of 29 which seems to imply that MySql is using the AUTO_INCREMENT on the CUSTOMER table to generate the Id automatically and ignoring the Id generation from the SEQUENCE table. If I remove the AUTO_INCREMENT from the CUSTOMER table I get errors on INSERTs since the Id field is set to NOT NULL and a Id was not provided from my application. Is it that the @TableGenerator doesn't work with MySql? Or am I doing something wrong?
public class Customer { @Id @GeneratedValue(generator="SeqGenName") @TableGenerator(name="SeqGenName", table="SEQUENCE", pkColumnName="SEQ_NAME", valueColumnName="SEQ_COUNT", pkColumnValue="SEQ_GEN") private Long id; The table generator defined in the preceding example would be mapped to the following table: SEQUENCE --------------------------------------------- | SEQ_NAME | SEQ_COUNT | | SEQ_GEN | 100 | --------------------------------------------- CREATE TABLE CUSTOMER( ID BIGINT(8) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, CUSTOMERSINCE DATE, VERSION BIGINT(8) UNSIGNED, NAME VARCHAR(255)); CREATE TABLE SEQUENCE( SEQ_NAME VARCHAR(50) NOT NULL PRIMARY KEY, SEQ_COUNT BIGINT(8) UNSIGNED); -- - Paul