0

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
Maria Gálvez
  • 187
  • 1
  • 1
  • 15

1 Answers1

1

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.

  • I did the first thing and it gave me this error: 2019-12-04 09:31:08.410 ERROR 22300 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: relation "rules" does not exist Position: 162 2019-12-04 09:31:08.424 INFO 22300 --- [nio-8080-exec-2] o.h.e.internal.DefaultLoadEventListener : HHH000327: Error performing load command : org.hibernate.exception.SQLGrammarException: could not extract ResultSet – Maria Gálvez Dec 04 '19 at 08:33
  • I just saw that it does not work for me because when doing the from schema.Table puts the scheme without parentheses and it only works for me when it is put in parentheses, as I do that in java it is put with parentheses when doing the insert – Maria Gálvez Dec 04 '19 at 09:21