TableGenerator improvement: set initial value when no record found
------------------------------------------------------------------
Key: HHH-2346
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2346
Project: Hibernate3
Type: Patch
Components: core
Versions: 3.2.1
Reporter: Fabrizio Giustina
Attachments: TableGenerator-init.diff
org.hibernate.id.TableGenerator is initialized during SchemaExport by creating a table and
inserting 0 as initial value.
When this generator is used to retrieve an id it throws an exception if no existing
records are available in such table. Although this is an uncommon situation, it would be
better to handle an empty table by simply starting from the default value instead of
throwing an exception.
My use case for example is the use of dbunit in a test db: after hibernate starts the db
is cleaned up (all the existing records removed) and only data needed a specific test are
loaded. Hibernate can't work with an empty hibernate_unique_key and so this table must
be handled carefully (excluded from cleanup or added to dbunit test data).
TableGenerator can however be easily modified to gracefully handle such situation: the
simple patch attached enhances TableGenerator by trying to insert the missing record
instead of immediately throw an exception. This can't hurt existing use cases since
the table initialization just saves from an IdentifierGenerationException.
Patch has been generated from hibernate trunk, 8 January 2007
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira