【发布时间】:2016-03-16 01:18:36
【问题描述】:
我在 linux 环境中部署 postgres 时遇到问题,但我不确定它是否相关。
- Linux 版本:9.3.11
- Windows 版本:9.5
我得到的错误:
2016-03-15_19:19:40.478 [http-nio-9090-exec-3] WARN o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 42P01
2016-03-15_19:19:40.479 [http-nio-9090-exec-3] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - ERROR: relation "rbac_roles" does not exist
Position: 125
2016-03-15_19:19:40.520 [http-nio-9090-exec-3] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause
org.postgresql.util.PSQLException: ERROR: relation "rbac_roles" does not exist
Position: 125
在我的由 Liquibase 创建的 windows 环境表定义如下:
-- Table: public.rbac_roles
-- DROP TABLE public.rbac_roles;
CREATE TABLE public.rbac_roles
(
tenantid character varying(255) NOT NULL,
id integer NOT NULL DEFAULT nextval('rbac_roles_id_seq'::regclass),
name character varying(255) NOT NULL,
urlprefix character varying(255),
CONSTRAINT pk_rbac_roles PRIMARY KEY (id),
)
WITH (
OIDS=FALSE
);
ALTER TABLE public.rbac_roles
OWNER TO postgres;
在我的 linux(问题)环境中,由 Liquibase 创建的表定义如下:
-- Table: public.rbac_roles
-- DROP TABLE public.rbac_roles;
CREATE TABLE public.rbac_roles
(
tenantid character varying(255) NOT NULL,
id serial NOT NULL,
name character varying(255) NOT NULL,
urlprefix character varying(255),
CONSTRAINT pk_rbac_roles PRIMARY KEY (id),
)
WITH (
OIDS=FALSE
);
ALTER TABLE public.rbac_roles
OWNER TO postgres;
Spring Jpa 对象如下所示:
@Entity(name = "rbac_roles")
public class Role implements HasTenantId {
@Id
@SequenceGenerator(name="roles_seq", sequenceName = "rbac_roles_id_seq")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "roles_seq")
private int id;
...
Liquibase 配置如下所示:
<createTable tableName="rbac_roles">
<column name="tenantid" type="varchar(255)">
<constraints primaryKeyName="pk_roles" nullable="false" />
</column>
<column name="id" autoIncrement="true" type="integer">
<constraints primaryKey="true" nullable="false" />
</column>
...
</createTable>
成功创建表 rbac_roles 但 ID 看起来不同
我做错了什么,为什么行为不同?
【问题讨论】:
-
您发布的实体
RolePermission与rbac_role表无关。可能是,您想发布与rbac_role表相关的不同实体? -
你说得对,谢谢,我已经编辑了帖子
-
更新:在 linux 上更新到 9.5 版似乎问题已解决(Id 仍然是串行的)
标签: spring hibernate postgresql jpa liquibase