我正在使用Spring Boot和PostgreSql作为数据库开发的项目。
我在PostgreSql中为我的user_seq
表创建了一个序列user
CREATE SEQUENCE "USER_MGMT"."USER_SEQ"
INCREMENT 1
START 1000
MINVALUE 1000
MAXVALUE 99999999
CACHE 1;
ALTER SEQUENCE "USER_MGMT"."USER_SEQ"
OWNER TO postgres;
这是我的user
表
CREATE TABLE "USER_MGMT"."USER"
(
"USER_ID" bigint NOT NULL DEFAULT nextval('"USER_MGMT"."USER_SEQ"'::regclass),
"FIRST_NAME" character varying(30) COLLATE pg_catalog."default" NOT NULL,
"LAST_NAME" character varying(50) COLLATE pg_catalog."default" NOT NULL,
"EMAIL_ID" character varying(70) COLLATE pg_catalog."default" NOT NULL,
"DESK_NUMBER" bigint,
"MOBILE_NUMBER" bigint,
"IS_ACTIVE" boolean NOT NULL DEFAULT true,
"CREATED_BY" character varying(70) COLLATE pg_catalog."default",
"MODIFIED_BY" character varying(70) COLLATE pg_catalog."default",
"DATE_CREATED" timestamp without time zone,
"DATE_MODIFIED" timestamp without time zone,
CONSTRAINT "USER_ID_PK" PRIMARY KEY ("USER_ID"),
CONSTRAINT "EMAIL_ID_UK" UNIQUE ("EMAIL_ID"),
CONSTRAINT "MOBILE_NUMBER_UK" UNIQUE ("MOBILE_NUMBER")
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE "USER_MGMT"."USER"
OWNER to postgres;
我正在为此用户表创建一个JPA实体
@Entity
@Table(name = "`USER`")
@ToString
@EqualsAndHashCode
public class User extends Auditable<String> {
/**
*
*/
private static final long serialVersionUID = 5351767213835401599L;
@Id
@SequenceGenerator(name = "USER_ID", sequenceName = "USER_SEQ", allocationSize = 1)
//Tried this also but not works
@SequenceGenerator(name = "USER_ID", sequenceName = "`USER_SEQ`", allocationSize = 1)
@GeneratedValue(generator = "USER_ID", strategy = GenerationType.SEQUENCE)
@Column(name = "`USER_ID`")
private Long userId;
@Column(name = "`FIRST_NAME`")
private String firstName;
将数据插入此用户表时,我收到错误消息称user_seq
不可用。
ERROR: relation "USER_MGMT.user_seq" does not exist
即使我在实体中以大写字母提到,它也是小写的。对于所有表和序列,这必须是大写的。在实体中有什么我错过的吗?