在JPA中重置序列 [英] Reset sequence in jpa
问题描述
我将spring boot 2与spring数据jpa,hibernate和posgres一起使用. 我需要在一年中的每1天重置一个序列,因为我们使用的是当前+''+序列ID.
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.
是否可以使用jpa重置序列?
Is there a way to reset a sequence with jpa?
推荐答案
不存在用于重置序列的纯JPA方法,并且并非所有数据库都支持重置序列.话虽如此,您可以尝试使用本地查询(em.createNativeQuery(...).executeUpdate()
)或此解决方案如果您绝对必须使用JPA作为存储过程API ,工作.
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.
这篇关于在JPA中重置序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!