I designed an ID Generator Hibernate class that is multi-platform friendly (similar to native id generator) but additionally provided for safe values in a distributed database environment. I wanted something that could be implemented natively on many databases (i.e. Oracle, Firebird, MySQL, etc.) without the need for loading extra library code into the database (i.e. Oracle 8 doesn't support out of the box UUIDs as SQL-Server does).
Often this is done on the database side by having a numeric database identifier used as part of the id. For example if using a two digit numeric database id and sequences the code on the dabase side would be similar to the following for Oracle:
Code:
SELECT S_TableIDSeq.NEXTVAL * 100 + v_DBID INTO :NEW.SCode FROM DUAL;
The above would normally be used in an insert trigger where v_DBID is the database id retrieved via a lookup table on the database or a function, etc.
The numeric database identifier is only guaranteed to be unique by design vs inherently unique and does require manual assignment of some sort or other. This has been an acceptable compromise in the past.
I didn't want to use the "assigned" generator as I wanted to take advantage of the auto-generation of the IDs.
The new generator can take advantage like the native generator of whether the generator should be based on a sequence, a table hi-lo or an identity. I've extensively tested with Oracle, Firebird and MySQL. It has been in use in a manufacturing machine automated data collection environment for the past 3 months. It has two additional parameters (compared to the native generator): databaseID and multiplier. Both are optional as the databaseID can be set/retrieved through a DatabaseIDSingleton class which was useful for me as I could set this DatabaseIDSingleton value at the onset of the program based on a query from the database connected to and therefore if the database connected to it switched it required no manual change of databaseID property in the mapping files. However, if the multiplier is ommitted it will ignore the databaseID and behave exactly like the native generator. I thought this would be useful as the same generator could be used whether in a distributed environment (multiplier parameter required) and in a non distributed enviroment (multiplier parameter not required).
The question is then to incorporate this new capability would it be best to extend the native class or create an entirely new class?
Does the Hibernate group want me to contribute this to the project?
In any case I'll post the code for the two classes as a reply to this thread and hopefully with a simple enough example of how the Singleton is intended to be used (when opting to use this vs a mapping file provided databaseID).