# Hibernate 4 to 5 migration with existing Table-Based generators

**URL:** <https://discourse.hibernate.org/t/hibernate-4-to-5-migration-with-existing-table-based-generators/4405>\
**Category:** Hibernate ORM\
**Created:** [July 17, 2020, 1:21pm UTC](https://discourse.hibernate.org/t/hibernate-4-to-5-migration-with-existing-table-based-generators/4405 "2020-07-17T13:21:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diederich](https://avatars.discourse-cdn.com/v4/letter/d/aca169/32.png) [@Diederich](https://discourse.hibernate.org/u/Diederich)\
**Post date:** [July 17, 2020, 1:21pm UTC](https://discourse.hibernate.org/t/hibernate-4-to-5-migration-with-existing-table-based-generators/4405/1 "2020-07-17T13:21:05Z")

</div>

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

```auto
@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 `GenerationType.TABLE` .

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

```auto
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/](https://vladmihalcea.com/hibernate-hidden-gem-the-pooled-lo-optimizer/)
