jpa-entity-generator icon indicating copy to clipboard operation
jpa-entity-generator copied to clipboard

Double quotes on id field causes failures with sequences

Open marcodelpercio opened this issue 4 years ago • 2 comments

Hi,

I decided to try this plugin to generate entities from an existing table in PostgreSQL. The table name is apilog CREATE TABLE public.apilog ( id bigserial NOT NULL, userid int4 NOT NULL, uri varchar(50) NOT NULL, "method" varchar(10) NOT NULL, calltimestamp timestamp NOT NULL, CONSTRAINT api_log_pk PRIMARY KEY (id) ); Because the primary key id is a serial type, there's a sequence automatically generated by PostgreSQL named "apilog_id_seq". Everything works fine in PostgreSQL and I can insert records without specifying an id to have it automatically generated by the sequence (as expected). However the problem comes because of the JPA Entity generated by this plugin. In fact the entity generated is like this.

`@Data @Entity(name = "org.oneocean.entities.Apilog") @Table(name = "apilog") public class Apilog {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "\"id\"", nullable = false) private Long id; ... ... `

You see those additional double quotes in the column name? They actually break the JPA entity and whenever I try to persist (or merge) a new entity PostgreSQL raises the following error:

2020-07-01 12:35:41,214 ERROR [org.hib.eng.jdb.spi.SqlExceptionHelper] (executor-thread-2) ERROR: relation "apilog_"id"_seq" does not exist

For some reason the name of the column "id" ends up in the sequence name with the additional double quotes and obviously such sequence doesn't exist. So the result is that I cannot merge/persist any of the entities generated with this plugin. I understand that the purpose of having the additional double quotes is to escape column names but if the side-effect is that the entity is broken it's just not worth having it. Can we disable the additional double quotes around every column name please?

Many thanks

marcodelpercio avatar Jul 01 '20 13:07 marcodelpercio