0

I have a problem where @GeneratedValue(strategy=GenerationType.AUTO) is not working properly. I have the error saying that kcyn.hibernate_sequence does not exist.

I read to following topic : hibernate could not get next sequence value. It says that I should change AUTO by IDENTITY. But then, I have an error saying that a NULL value is added into primary key.

If I am starting from an non existing table, with AUTO strategy, hibernate auto-magically creates airroute table with an hibernate_sequence table.

But, since I want to work with an existing database, my question would be, which GenerationType should I use in order to have my id automatically generated?

package models;
import javax.persistence.*;    
@Entity
public class Airroute {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    public Long id;    
    public String label;        
    public String spokenname;        
    public Boolean internal;        
    public String descr;        
    public String direction;
}

UPDATED

Maxsim=# \d+ "KCYN-GOLD-USMC_3_141_553".airroute
                    Table "KCYN-GOLD-USMC_3_141_553.airroute"
   Column   |      Type      | Modifiers | Storage  | Stats target | Description
------------+----------------+-----------+----------+--------------+-------------
 id         | numeric(11,0)  | not null  | main     |              |
 label      | character(8)   |           | extended |              |
 spokenname | character(60)  |           | extended |              |
 internal   | boolean        |           | plain    |              |
 descr      | character(250) |           | extended |              |
 direction  | character(1)   |           | extended |              |
Indexes:
    "airroute_pkey" PRIMARY KEY, btree (id)
peterphonic
  • 951
  • 1
  • 19
  • 38

1 Answers1

0

As any JPA doc would tell you,

  • AUTO means let the JPA provider do whatever it likes (so you may not get what you want)
  • SEQUENCE will use a SEQUENCE in the RDBMS (which Postgresql supports, so an option for your case)
  • TABLE will create a table in the DB to hold id values (also an option for your case)
  • IDENTITY will require a column type of SERIAL which you haven't got on that column (not an option).

For SEQUENCE and TABLE the JPA provider will need to be able to create either a SEQUENCE or a TABLE respectively in that schema (and be configured to do so)