首页 > 解决方案 > Postgres 查找名称错误的关系

问题描述

在 Postgres 中,我有以下表格:

CREATE TABLE punching_history (
    id_punching serial NOT NULL,
    punching_date timestamp without time zone,
    -- other fields
    CONSTRAINT punching_pk PRIMARY KEY (id_punching)
);

CREATE TABLE punching()
INHERITS (punching_history);

和这个序列(由 punching_history 的序列字段自动生成):

CREATE SEQUENCE punching_history_id_punching_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

插入(持久)到冲压表中有效,但有时,显然没有理由,它会失败并出现以下错误:

"HTTP 500 Internal Server Error - could not extract ResultSet 
org.postgresql.util.PSQLException: ERROR: relation 
<schema_name>.punching_id_punching_seq does not exist Position: 16"

在 Hibernate 中,主键映射为:

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID_PUNCHING", unique = true, nullable = false)
private Integer idPunching;

为什么 Postgres 寻找 punching_id_punching_seq 关系?它一直是punching_history_id_punching_seq。

谢谢

标签: postgresqlhibernate

解决方案


推荐阅读