Maria Gálvez
Maria Gálvez

Reputation: 307

How to do in spring boot that connects to a scheme in a database and not to the public

I have a Spring Boot api that connects to a database in postgresql,In the database I have two schemes, one of my own and the public. when inserting the table that I have in my scheme is created in the public and inserted there. I have tried to put in the entity the name of my scheme but it gives me an error and says that it does not exist, I do not know if it is necessary to do so:

@Entity
@Table(  name = "rules" , schema = "eschema1")

This is my application.properties:

spring.datasource.url=jdbc:postgresql://15.98.0.65:5432/database
spring.datasource.username=postgres
spring.datasource.password=
spring.datasource.driver-class-name=org.postgresql.Driver


spring.jpa.show-sql=true

spring.jpa.hibernate.ddl-auto=none

Upvotes: 0

Views: 1727

Answers (1)

user330315
user330315

Reputation:

I see three solutions:

  1. add ?currentSchema=eschema1 to the connection URL

  2. permanently change the search path for that user:

    alter user postgres set search_path = 'public,eschema1';
    
  3. Tell your obfuscation layer (=ORM) to prefix the tables with the schema you have configured. How exactly that is done, I don't know.


I would strongly suggest you use a different user than postgres - even if it's just for testing purposes.

Upvotes: 1

Related Questions