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.
Latest released version of Hibernate (4.2.5).
Test case reproduced it on HSQLDB, but should be reproducible on any database platform.