How to prevent SELECT queries from SequenceGenerator
See original GitHub issueIf I use the pooled SequenceGenerator
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "my_seq")
@SequenceGenerator(name = "my_seq", sequenceName = "my_seq", allocationSize = 10)
then my query assertions fail sometimes, because due to the pooling, the statement(s)
select nextval ('my_seq')
are sometimes called before and sometimes during the test.
It works, when I change this property to none
spring.jpa.properties.hibernate.id.optimizer.pooled.preferred=none
Is this approach recommended or is there a better way to assert query count when using pooled sequence generator?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Generate sequence NexVal without execute select query
My class is not Entity there is code fragment @SequenceGenerator(name="seqUniqueKeyGenerator",sequenceName ...
Read more >How to use Hibernate identifier sequence generators properly
Using a SEQUENCE generator is a better alternative since the identifier can be generated prior to executing the INSERT statement.
Read more >Hibernate Tips: How to use a custom database sequence
First of all, you have to annotate the primary key attribute with the @GeneratedValue annotation and set GenerationType.SEQUENCE as the strategy.
Read more >JPA + Hibernate - @SequenceGenerator Examples - LogicBig
SELECT * FROM MyEntity2 5 6. The above output shows that generated sequence has first three values consistent with our SequenceGenerator:.
Read more >Sequence Generator transformation
We want to hear from you! You can now add comments to any guide or article page. To provide feedback and suggestions, log...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

For our project, I wrote an exclusion listener. Works like a charm:
It’s not a good idea to disable identifier optimizers. The same select queries are executed in production too, so you should check the actual statement count.