I've been following with interest Charles Lee's post over at the TSS about "Hibernate - A MySQL Enabler?". MySQL has always been well-supported by Hibernate, so it's good to see yet another project find that the two together can be a powerful pair (and keep vendor lock-in at bay).
The key issue that Hyperic ran into is that MySQL doesn't have sequences, but instead has identity-like columns. It seems that many folks with legacy data models run into the same issue.
Maybe it was serendipity that Steve Ebersole and the Hibernate team have delivered SequenceStyleGenerators in Hibernate 3.2.3 (and with even a bit earlier delivery, maybe Hyperic wouldn't have had to roll their own implementation).
I went and took a look at Hibernate's implementation, and it's straightforward, so it should work for a lot of situations.
I did end up chatting with Steve about one optimization that would work for MySQL, which is that there is a construct where a query can both do an update and return a value in one atomic operation, thus not requiring an in-progress transaction, and cutting down on round-trip latency. (Yes, I know that SQL Server 2005 has a similiar mechanism, do any other databases have anything similar?).
For those that are interested, it looks similar to this (from the manual):
Create a table to hold the sequence counter and initialize it:
mysql>CREATE TABLE sequence (id INT NOT NULL);
mysql>INSERT INTO sequence VALUES (0);
Use the table to generate sequence numbers like this:
mysql>UPDATE sequence SET id=LAST_INSERT_ID(id+1);
mysql>SELECT LAST_INSERT_ID();
The nice thing about doing this from JDBC (or most clients for that matter), is that you don't actually need the "SELECT LAST_INSERT_ID()" statement, MySQL sends that to the client automatically as part of the UPDATE statement. In JDBC you get to it via Statement.getGeneratedKeys().
If you want to ask Charles some questions in-person about their experience doing the migration, you could come to the MySQL Users Conference and see his session "Using Hibernate to Ease the Migration to Open Source Databases".