0

I was already searching for a solution but I cannot find any.

My problem is that I cannot my Postgres database, called IncomeOutgo, via Hibernate.

I always get this error message when calling my Thymeleaf/HTML website.

enter image description here

So does my application.properties look like

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.show-sql=true
spring.datasource.url=jdbc:postgresql://192.168.0.227:5432/IncomeOutgo
spring.datasource.username=postgres
spring.datasource.password=XXX
#spring.jpa.properties.hibernate.format_sql=true

So does my table look like in Postgres (DBeaver):

enter image description here

And last but not least so does my Domain/Entity look like:

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@Table
public class IncomeOutgo extends AbstractPersistable<Long> {

    @Version
    @Column(name ="id")
    private Long id;

    @Column(name="dayofweek")
    private Date dayofweek;

    @Size(min = 5, max = 50)
    @Column(name ="person")
    private String person;

    @Min(0)
    @Column(name ="version")
    private Integer version;

    @Column(name="income")
    private int income;

    @Column(name="outgo")
    private int outgo;
}

Maybe, someone can tell me what my error is?

Thanks in advance!

Bernd
  • 593
  • 2
  • 8
  • 31
  • Try explicit table name using @Table annotation – Lesiak Feb 16 '21 at 09:21
  • I tried it with @Table="incomeoutgo" (omitting spring.datasource.url=jdbc:postgresql://192.168.0.227:5432/--OMITTED--) error message: org.postgresql.util.PSQLException: ERROR: relation "incomeoutgo" does not exist as well as @Table="IncomeOutgo" and omitting spring.datasource.url=jdbc:postgresql://192.168.0.227:5432/--OMITTED--) error message: org.postgresql.util.PSQLException: ERROR: relation "income_outgo" does not exist – Bernd Feb 16 '21 at 09:31
  • 1
    What is your default schema? Try `@Table(name="incomeoutgo", schema="IncomeOutgo")` I guess you already checked the grants on the table. – Lesiak Feb 16 '21 at 09:34
  • Try also `@Table(name="\"incomeoutgo\"")` – SternK Feb 16 '21 at 09:35
  • To answer a question: SELECT current_schema(); yields IncomeOutgo. Then I tried your suggestions (always using spring.datasource.url=jdbc:postgresql://192.168.0.227:5432/): @Table(name="incomeoutgo", schema="IncomeOutgo"); error_message: ERROR: relation "income_outgo.incomeoutgo" does not exist and for @Table(name="\"incomeoutgo\""); error_message: ERROR: relation "incomeoutgo" does not exist – Bernd Feb 16 '21 at 09:47
  • To my eyes your shema name gets transformed to snake_case, and hence the table is not found. Try changing PhysicalNamingStrategy (or schema name in db, if you have freedom to do so). See https://stackoverflow.com/a/61760535/1570854 – Lesiak Feb 16 '21 at 10:04

1 Answers1

0

I was able to make it work now. Lesiak´s hint with the schema name made me do a workaround.

I created a new database: incomeoutgo (lower letter case), and under schema: public, a new table: incomeoutgo with lower letters, too.

enter image description here

And so does my Domain definition look like:

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@Table(name="incomeoutgo", schema = "public")
public class IncomeOutgo extends AbstractPersistable<Long> {

    @Version
    @NotNull
    @Column(name ="id")
    private Long id;

    @Column(name="dayofweek")
    private Date dayofweek;

    @Size(min = 5, max = 50)
    @Column(name ="person")
    private String person;

    @Min(0)
    @Column(name ="version")
    private Integer version;

    @Column(name="income")
    private int income;

    @Column(name="outgo")
    private int outgo;
}
Bernd
  • 593
  • 2
  • 8
  • 31