quarkus: Manually created sequence in postgresql is not working correctly
Describe the bug
Given an Entity with a Long type @Id column, when manually creating the sequence for the id column CREATE SEQUENCE giftSeq the behaviour of assigning is broken.
Expected behavior id’s assignment follow the natural series development 1,2,3,…
Actual behavior The id’s assigned to follow the path 1,2,-46,-45,… until a collision happens
To Reproduce
docker run --ulimit memlock=-1:-1 -d --rm=true --memory-swappiness=0
--name postgres-quarkus-hibernate -e POSTGRES_USER=hibernate
-e POSTGRES_PASSWORD=hibernate
-p 5432:5432 postgres:10.5
docker exec -ti postgres-quarkus-hibernate psql -U hibernate -c "CREATE DATABASE hibernate_db"
docker exec -ti postgres-quarkus-hibernate psql -U hibernate -c "CREATE TABLE Gift(id bigint primary key, name text); CREATE sequence giftSeq;" hibernate_db
Reproducer example here, with test case https://github.com/svinther/quarkus-problem-messysequence
Configuration
%test.quarkus.hibernate-orm.log.sql=true
%dev.quarkus.hibernate-orm.log.sql=true
%dev.quarkus.hibernate-orm.log.bind-param=true
quarkus.hibernate-orm.database.generation=none
# datasource configuration
quarkus.datasource.db-kind=postgresql
quarkus.datasource.username=hibernate
quarkus.datasource.password=hibernate
quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/hibernate_db
Environment (please complete the following information):
- Openjdk 11
- Quarkus 1.7.0.Final
Additional context If creating the sequence as “CREATE sequence giftSeq start 1 increment 50;” as seems to be hibernates default behavior, then everything seems to work correctly
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 25 (14 by maintainers)
I think we did in ORM 6.0, at least to some extent?
https://github.com/hibernate/hibernate-orm/blob/6.0/migration-guide.adoc#implicit-identifier-sequence-and-table-name
By the way, heads-up to @Sanne: we may need to expose this configuration property in Quarkus 3 to provide a migration path for users who created their schema with Hibernate ORM 5? Maybe that should be part of a more general effort to provide a migration guide to users of the Hibernate ORM extension for Quarkus, because I suspect there are other breaking changes.
We got sidetracked, though. I must admit I’m not sure I understand the exact problem we need to solve in order to close this issue.
I think the conclusion was there:
(Sanne)
(Gavin)
Do I understand correctly that you would like to log a warning on startup (upon validating the schema?) when there is a
@GeneratedValue(name = "gitSeq")without a corresponding@SequenceGenerator, and we cannot find the corresponding sequence in the schema?I think you are right. I followed this quickstart guide: https://quarkus.io/guides/hibernate-orm without thinking too much, I guess the guide should be corrected ?