Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 液化酶与弹簧jpa_Spring_Hibernate_Postgresql_Jpa_Liquibase - Fatal编程技术网

Spring 液化酶与弹簧jpa

Spring 液化酶与弹簧jpa,spring,hibernate,postgresql,jpa,liquibase,Spring,Hibernate,Postgresql,Jpa,Liquibase,我在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

我在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
在我的windows环境中,由Liquibase创建的表定义如下所示:

-- 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;
-- 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;
在我的linux(问题)环境中,由Liquibase创建的表定义如下所示:

-- 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;
-- 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;
 <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>

Liquibase配置如下所示:

@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;
 <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_角色已成功创建,但ID看起来不同


我做错了什么,为什么行为不同?

在JPA注释中,您使用的是序列生成器,但在变更日志中,ID属性有一个自动增量类型

<createTable tableName="rbac_roles">
    <column name="tenantid" type="varchar(255)">
        <constraints primaryKeyName="pk_roles" nullable="false" />
    </column>

    <!-- HERE you specify autoincrement -->
    <column name="id" autoIncrement="true" type="integer">
        <constraints primaryKey="true" nullable="false" />
    </column>

    ...

</createTable>

...
这是令人困惑的,我不知道为什么这段代码在windows和linux上生成不同的表,也许你的postgresql不是同一版本

请修复您的变更日志并放置以下内容

<createTable tableName="rbac_roles">
    <column name="tenantid" type="varchar(255)">
        <constraints primaryKeyName="pk_roles" nullable="false" />
    </column>

    <!-- Removed autoincrement -->
    <column name="id" type="integer">
        <constraints primaryKey="true" nullable="false" />
    </column>

    ...

</createTable>

<!-- HERE I specify sequence -->
<createSequence sequenceName="rbac_roles_id_seq" incrementBy="1"/>

...

这样,它应该在两个系统上生成相同的表。

您发布的
RolePermission
实体与
rbac\u角色
表无关。可能是,您想发布一个与
rbac\u角色
表相关的不同实体?您是对的,谢谢,我已经编辑了postUpdate:在linux上更新到9.5版似乎是个问题,已经解决(Id仍然是串行的)谢谢!检查它,同时我用Linux版本:9.3.11 Windows版本:9.5更新了帖子