Multiple table generator in Hibernate3

by Dejan Bosanac

Some time ago I needed a unique identifier generator that will look up a value in a simple name-value kind of database table. Project's database layer was based on Hibernate2 and since I couldn't find such a solution I have implemented a MultiTableGenerator which I have blogged about here.

The project was finished and I moved on. Since then, many people reported that my solution was not compatible with Hibernate3 but unfortunately I never found time to fix it. Luckily, I was recently reported that Hibernate team introduced this functionality in Hibernate3. The class is called org.hibernate.id.MultipleHiLoPerTableGenerator. As I can see, it is not documented in the latest version of the reference documentation yet, but you can find a description in a JavaDoc documentation.

The configuration syntax of these two solutions looks similar (parameter names have been changed), which makes it even easier to port functionality if you are migrating to Hibernate3. It is good to see useful stuff becoming a standard part of the library.

1 Comments

Alexis
2006-09-26 07:17:13
This generator is really useful actually.
Having all id labels in a single table improves clarity and maintenance.
However beware, this generator has a jdbc connection leakage, what could very annoying:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1669


We should wait for release 3.2 for a fix.


Alexis