问题描述
我正在编写一个Spring Boot Web应用程序,并使用Postgres数据库来保留我的数据。我使用 create table用户(id bigserial主键不为空,名称文本不为空;
)在Postgres中创建了一个表,并确定了其 sequence_name
通过查看模式(在本例中为 user_id_seq
)在我的 User
实体中在Spring Boot中,我添加了以下内容:
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.
推荐答案
请确保将search_path设置为该序列所属的架构。即使所讨论的表符合模式要求,也必须适当设置search_path。
Make sure your search_path is set to the schema that the sequence belongs to. Even if the table in question is schema-qualified, the search_path must also be set appropriately.
这篇关于序列不存在-Postgres / Spring Boot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!