Generating an ID with org.hibernate.id.enhanced.TableGenerator can hang the application if HIBERNATE_SEQUENCES has NULL value

Description

When enhanced table-based ID generator (org.hibernate.id.enhanced.TableGenerator) is used, it is generating new IDs based on a database table, named HIBERNATE_SEQUENCES by default. The NEXT_VAL column in this table is generated as nullable. If it contains a NULL value however the ID generation hangs and never completes, generator code is running SELECT and UPDATE queries in an infinite loop.
A test case is attached, it should only require Hibernate and HSQLDB to run.

Environment

Latest released version of Hibernate (4.2.5).
Test case reproduced it on HSQLDB, but should be reproducible on any database platform.

Assignee

Unassigned

Reporter

Sergey Parhomenko

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Minor
Configure