Raibaz
Raibaz

Reputation: 9710

Liquibase generating empty ALTER SEQUENCE changes

I have a set of JPA entities that have their IDs generated by a sequence:

@GenericGenerator(
    name = "catalog_items_history_seq",
    strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
    parameters = [
        (Parameter(name = "sequence_name", value = "catalog_item_history_sequence")),
        (Parameter(name = "initial_value", value = "1")),
        (Parameter(name = "increment_size", value = "1"))
    ]
)

class CatalogItemHistory {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "catalog_items_history_seq")
    var id: Long = -1
}

When I run the diffChangeLog gradle task the first time, i get the proper CREATE SEQUENCE statements and the sequences are created ok.

However, if i run the task again, my changelog contains changes like this:

<changeSet author="raibaz (generated)" id="1582110272824-1">
    <alterSequence sequenceName="catalog_item_history_sequence"/>
</changeSet>

Which result in a syntax error, because the SQL they produce is ALTER SEQUENCE catalog_item_history_sequence which is invalid as it's not actually altering anything.

When i run liquibase to update my database schema, then, what i get is:

Caused by: liquibase.exception.DatabaseException: ERROR: syntax error at end of input
  Posizione: 52 [Failed SQL: (0) ALTER SEQUENCE public.catalog_item_history_sequence]

My database is PostgreSQL 12.

What am I missing? Is there a way to prevent liquibase from creating these changes?

Upvotes: 10

Views: 1875

Answers (1)

Lautert
Lautert

Reputation: 520

This was fixed on liquibase-hibernate5 version 4.12.0 . PR https://github.com/liquibase/liquibase-hibernate/pull/354 fixed this issue by implementing a new ChangedSequenceChangeGenerator .

Upvotes: 0

Related Questions