0

I am working on a simple spring endpoint. My current db table sql is:

CREATE TABLE develop.usermetrics (
    metricId SERIAL PRIMARY KEY,
    uid varchar(12),
    deptCode varchar(10),
    orgGroup varchar(10),
    orgUnit varchar(10),
    orgCode varchar(10),
    workLocationCode varchar(10),
    campusId varchar(20),
    userRole varchar(50),
    metricDate timestamp
);

And my entity contains:

    @Table(name = "usermetrics")
    @Entity
    public class UserMetricsEntity {

    @Id
    @Column(name = "metricId")
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long metricId;

    @Column(name = "uid")
    private String uid;

    @Column(name = "deptCode")
    private String deptCode;

    @Column(name = "orgGroup")
    private String orgGroup;

    @Column(name = "orgUnit")
    private String orgUnit;

    @Column(name = "orgCode")
    private String orgCode;

    @Column(name = "workLocationCode")
    private String workLocationCode;

    @Column(name = "campusId")
    private String campusId;

    @Column(name = "userRole")
    private String userRole;

    @Column(name = "metricDate")
    private LocalDateTime metricDate;

When calling the save method of the repository I get the error:

UserMetricsEntity{metricId=null, uid='105735781', deptCode='Z05511', orgGroup='F&O', orgUnit='CIO', orgCode='0F', workLocationCode='MPG', campusId='GDLPLANT', userRole='Fullstack Developer', metricDate=2021-11-01T12:45:22.588191}
    2021-11-01 12:45:23.029  WARN 57529 --- [nio-8082-exec-3] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 42703
    2021-11-01 12:45:23.029 ERROR 57529 --- [nio-8082-exec-3] o.h.engine.jdbc.spi.SqlExceptionHelper   : ERROR: column "campus_id" of relation "usermetrics" does not exist

The first line of the log being a toString of the Entity.

Faramarz Afzali
  • 726
  • 1
  • 10
  • 24
  • Are you sure the table is properly created? – João Dias Nov 01 '21 at 19:24
  • Yes, in pgadmin I ran: INSERT INTO develop.usermetrics (uid,deptCode,orgGroup,orgUnit,orgCode,workLocationCode,campusId,userRole,metricDate) VALUES ('105735781','Z05511','F&O','CIO','0F','MPG','GDLPLANT','Fullstack Developer','2021-11-01 12:29:54.577118') and it was added succesfully – Kalio O'Farril Nov 01 '21 at 19:29
  • 2
    Look at https://stackoverflow.com/questions/28544541/jpa-column-with-incorrect-underscore and https://stackoverflow.com/questions/25283198/spring-boot-jpa-column-name-annotation-ignored answers You should change naming strategy or use lowercase column names in your annotations – Gennady Nov 01 '21 at 19:32
  • Yes! Actually just was checking that, even though I named with camel case on the table creating sql, pgadmin changed the caps to lowercase. I changed the naming convention on the entity class to all lowercase and it worked. Thanks! – Kalio O'Farril Nov 01 '21 at 19:39

1 Answers1

1

Even though I named with camel case on the table creating sql, pgadmin changed the caps to lowercase. I changed the naming convention on the entity class to all lowercase and it worked.