序列不存在 - Postgres/Spring Boot [英] Sequence does not exist when it does - Postgres/Spring Boot

查看:97
本文介绍了序列不存在 - Postgres/Spring Boot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 Spring Boot 网络应用程序并使用 Postgres 数据库来保存我的数据.我使用 create table user (id bigserial primary key not null, name text not null; 在 Postgres 中创建了一个表,并通过查看模式识别了它的 sequence_name (在这种情况下,就是user_id_seq).然后,在我的Spring Boot的User实体类中,我添加了以下内容:

I am writing a Spring Boot web-app and using a Postgres db to persist my data. I created a table in Postgres using create table user (id bigserial primary key not null, name text not null; and identified its sequence_name by looking at the schema (in this case, it is user_id_seq). Then, in my User entity class in Spring Boot, I added the following:

@Entity
@Table(name = "user")
public class User implements Serializable {

    @Id
    @SequenceGenerator(name = "user_local_seq", sequenceName = "user_id_seq", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_local_seq")
    private Long id;
...

确保 sequenceName 与我之前看到的相符.现在,当我启动我的 Spring Boot 应用程序时,我能够成功启动它,但我在跟踪中收到以下错误":

making sure that the sequenceName matches what I saw earlier. Now when I start my spring boot app, I am able to successfully boot it but I get the following "error" in the trace:

main] org.hibernate.tool.hbm2ddl.SchemaExport  : ERROR: sequence "user_id_seq" does not exist

我杀死了应用程序并再次启动它,这一次,我得到了:

I killed the app and started it again and this time, I got:

main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: drop sequence user_id_seq
main] org.hibernate.tool.hbm2ddl.SchemaExport  : ERROR: sequence "user_id_seq" does not exist

这是什么意思?我错过了什么吗?任何帮助/见解表示赞赏.

What does this mean? Am I missing something? Any help/insight is appreciated.

推荐答案

这里是洞察力.

ERROR: sequence "user_id_seq" does not exist

这意味着您的序列要么不存在于数据库中用户无权访问它.

It mean your sequence either not exist in database OR the user doesn't has permission to access it.

解决方案:

  1. 通过命令ds检查数据库中的user_id_seq
  2. 向特定用户授予序列访问权限.
    GRANT ALL ON SCHEMA schema_name TO user_name 中的所有序列;
  1. Check user_id_seq in database by command ds
  2. Grant access on sequence to specific user.
    GRANT ALL ON ALL SEQUENCES IN SCHEMA schema_name TO user_name;

这篇关于序列不存在 - Postgres/Spring Boot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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