10

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?

Raibaz
  • 9,280
  • 10
  • 44
  • 65
  • Looks like there's been a bug open since 2015 about this: https://liquibase.jira.com/browse/CORE-2495 – Raibaz Feb 19 '20 at 13:30
  • any workaround here? How did you solve this? – Md. Farhan Memon Apr 10 '20 at 12:05
  • I also faced this problem but I guess they didn't fix that bug. – Oguzhan Cevik Jan 26 '22 at 06:25
  • @Md.FarhanMemon For a workaround, you can use excludeObjects attribute to exclude particular objects from the diff. Could use this when doing the diff and exclude the sequences.. hope this helps! – Eduard Uta Apr 28 '22 at 13:22
  • @EduardUta - wouldn't that skip generating sequence in the first time itself too? – Md. Farhan Memon May 03 '22 at 13:56
  • @Md.FarhanMemon I would assume that this workaround will be used not on first time/execution, but starting with the 2nd and so on (to avoid that error). First time the call should not exclude anything; further calls can exclude the sequences to avoid that particular error. Should be tested a little of course. – Eduard Uta May 03 '22 at 21:07

1 Answers1

0

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 .

Lautert
  • 376
  • 2
  • 5