Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double quotes on id field causes failures with sequences #33

Open
marcodelpercio opened this issue Jul 1, 2020 · 2 comments
Open

Double quotes on id field causes failures with sequences #33

marcodelpercio opened this issue Jul 1, 2020 · 2 comments

Comments

@marcodelpercio
Copy link

marcodelpercio commented Jul 1, 2020

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

@seratch
Copy link
Collaborator

seratch commented Jul 1, 2020

Can we disable the additional double quotes around every column name please?

This company (SmartNews) doesn't use PostgreSQL at all. So, I'm afraid that they won't make efforts to add the option for you (at least in the short term).

Also, I don't have the bandwidth to work on the feature for you. That said, as the original creator, I'm happy to review your pull requests if you're interested in contributing to this project.

If you're in a hurry, modifying this template file in your fork should work.

@andredesousa
Copy link

In my case, I created a special Gradle task:

task generateEntities() {
    dependsOn 'entityGen'
    doLast {
        ant.replace(token: "\\\"", value: '') {
            fileset(dir: 'src/main/java/app/entities')
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants