在JPA中重置序列 [英] Reset sequence in jpa

查看:192
本文介绍了在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆