Reset sequence in jpa

2019-08-16 17:33发布

I use spring boot 2 with spring data jpa, hibernate and posgres. I need to reset a sequence every 1 day of the year, because we use current + ''+ sequence id.

Is there a way to reset a sequence with jpa?

1条回答
叛逆
2楼-- · 2019-08-16 17:43

A pure JPA way to reset a sequence does not exist, and resetting sequences is not even supported by all databases. That being said, you could try this solution with a native query (em.createNativeQuery(...).executeUpdate()) or the stored procedure API if you absolutely must use JPA for the job.

查看更多
登录 后发表回答