I have been in an email debate about this, but have got no where, so I'm raising this in the forum, so that others can contribute.
Here are the facts:
Regardless of whether this is a sensible situation or not, all the ID fields on a database I am dealing with are defined as DECIMAL (11,0). Now you can debate the rights and wrongs of this, but to me there are two things of note:
1) I cannot change this situation, its a database I am stuck with, however stupid people may think it is to use DECIMALs as id fields
2) Obviously the designers of DB2 acknowledge the situation, as they support the use of DECIMAL as an identity field.
We do not use hibernate at the moment, so we determine the next key by ading one to the maximum key value on the file. This is the same concept for generating keys as the hibernate increment generator.
All our business objects hold the equivalent ID fields as BigDecimal. At the moment we manually map between these and the databse, which is why we want to use hibernate.
In the short term as part of an R&D project I decided to use the increment generator. In the long term I'll get the database changed to make all ID fields identity fields and then use the native generator.
Anyway I found out that the increment generator only supports ID fields of short, int and long. This is down to the IdentifierGeneratorFactory class only supporting the aforementioned field types.
I raised an ISSUE on JIRA to change this so that it supported BigDecimal as well. After all, the increment generator is supposed to just return the current maximum key field plus one, who cares what format the number is in as long as its an integer, and that includes DECIMAL or NUMERIC database fields with a scale of 0.
As a stop gap solution I wrote my own custom generator that effectively just adds BigDeicmal to the list of allowed return types. I'd far rather see the increment generator support NUMERIC and DECIMAL properly, and indeed an as yet unactioned patch,
http://opensource.atlassian.com/projects/hibernate/browse/HB-92
does the job a lot more elegantly than my bodge.
Do people think my suggestion is a reasonable one ? I was pretty unimpressed that my JIRA issue
http://opensource.atlassian.com/projects/hibernate/browse/HB-1138was closed with the one liner : u
sing a non-integer type for a surrogate key makes no sense