Skip to content
Advertisement

org.postgresql.util.PSQLException: ERROR: relation “app_user” does not exist

I have an application that I’m using spring boot and postgres. I’m getting this error when I try to create a user.

When I run this query on my database, I get the same error:

JavaScript

But if I change that to:

JavaScript

It works.

How can I configure that on my spring boot app?

dependencies in pom.xml:

JavaScript

application.properties:

JavaScript

My entity:

JavaScript

I’m calling this action from a form:

JavaScript

and this is my controller:

JavaScript

The validator that cath the error:

JavaScript

UserServiceImpl (@Service):

JavaScript

And the repository is a CrudRepository interface, and have no implementation:

JavaScript

And debuging the validator I could get this stack:

JavaScript

Thanks for the help!

Advertisement

Answer

PostgreSQL is following the SQL standard and in that case that means that identifiers (table names, column names, etc) are forced to lowercase, except when they are quoted. So when you create a table like this:

JavaScript

you actually get a table app_user. You apparently did:

JavaScript

and then you get a table "APP_USER".

In Spring, you specify a regular string for the table name, in capital letters, but that gets spliced into a query to the PostgreSQL server without quotes. You can check this by reading the PostgreSQL log files: it should show the query that Spring generated followed by the error at the top of your message.

Since you have very little control over how Spring constructs queries from entities, you are better off using SQL-standard lower-case identifiers.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement