We migrated from Hibernate 4 to 5, one major problem was the new generator, which generates the IDs for the table rows. Our old generators are all table based, like
@TableGenerator(name = TABLE_NAME + "_generator", table = ...) @GeneratedValue(strategy = GenerationType.TABLE ... private Long id;
The new default generator from Hibernate 5 doesn’t respect that correctly and generates new ids seemingly “from scratch”, so you get “Already existing ID” exceptions when new rows are inserted.
All clean solutions I found were based on the idea that Hibernate 4 was used previously in AUTO-Mode (
@GeneratedValue(strategy = GenerationType.AUTO) ), but we always used
The “dirty” solution: Add
<property name="hibernate.id.new_generator_mappings" value="false"/> to Hibernates
persistence.xml . The result: Our existing databases can be used without problems, except: Constant warnings from Hibernate
HHH90000015: Found use of deprecated [org.hibernate.id.MultipleHiLoPerTableGenerator] table-based id generator; use org.hibernate.id.enhanced.TableGenerator instead. See Hibernate Domain Model Mapping Guide for details.]]
My question is: How can we keep the original database, stop using deprecated code, and correctly create new rows with new IDs, not colliding with existing IDs?
Especially since it’s said Hibernates 5 pooled identifier generators are better than the table ones: https://vladmihalcea.com/hibernate-hidden-gem-the-pooled-lo-optimizer/