0

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,
netto
  • 135
  • 1
  • 3
  • 11
  • and what happens when you use "IDENTITY" generation strategy? i.e the thing that equates to "SERIAL" database type – Neil Stockton Mar 03 '17 at 08:57
  • I have an issue using "IDENTITY" but yes, it generates serial datatype. Please refer to this link for my issue using "IDENTITY" http://stackoverflow.com/questions/42239134/the-column-name-x-was-not-found-in-this-resultset-jpa – netto Mar 04 '17 at 00:24

1 Answers1

0

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

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29