简体   繁体   中英

JPA - Map Serial(Primary Key) Datatype for PostgreSQL

I'm developing a simple app and I used GenerationType.SEQUENCE for primary key and it generates int datatype in database. Is there a way to tell JPA through mapping that I want to generate serial datatype in database not int datatype?

Company:

    @Id
    @SequenceGenerator(
            name="Company_Id_seq",
            sequenceName="\"Company_Id_seq\"",
            schema="test",
            allocationSize=1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="Company_Id_seq")
    @Column(name = "\"Id\"", nullable = false)
    private Integer id;

PostgreSQL:

CREATE TABLE test."Company"
(
  "Id" integer NOT NULL,

What I want:

CREATE TABLE test."Company"
(
  "Id" serial NOT NULL,

SEQUENCE is not for use when you have an "auto-incrementing" column type in the datastore. For that situation you should use IDENTITY strategy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM