I have an empty Spring Boot application in which I want to load my data from a previous version. This data does already contain primary keys. Therefore I use Liquibase loadData method:
<column name="id" type="bigint" autoIncrement="${autoIncrement}">
<constraints primaryKey="true" nullable="false"/>
</column>
<loadData tableName="point_of_interest" separator=";" file="classpath:config/liquibase/data/public.poi.csv">
</loadData>
// the java annotations
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
This works as expected but the Hibernate sequence is not updated. Which results in duplicate primary keys if I want to save a new object.
What am I doing wrong?
Cheers, Daniel
My solution (copied form the jHipster team) to this problem is to increase the start value of the hibernate sequence. This allows you to insert all the data with IDs < startValue and so no collisions will occur:
<changeSet id="00000000000000" author="jhipster" dbms="postgresql,oracle">
<createSequence sequenceName="hibernate_sequence" startValue="20000" incrementBy="1"/>
</changeSet>