10

What I am currently doing in my application.properties file is:

spring.datasource.url=jdbc:postgresql://localhost:5432/myDB?currentSchema=mySchema

Isn't there another property for this? Since it looks hacky and according to a post (still finding the link sorry, will update later), it is only applicable to PostgreSQL 9.4.

3 Answers 3

15

Since this is quite old and has no proper answer yet, the right property to set is the following:

spring.jpa.properties.hibernate.default_schema=yourschema
Sign up to request clarification or add additional context in comments.

2 Comments

And what about JDBC configuration, not JPA?
Setting currentSchema=mySchema for JDBCTemplate is not working. I'm using postgres 12.
6

With SpringBoot 2.5.5 the only thing that work for me:

aplication.properties

spring.datasource.hikari.schema=my_schema

aplication.yml version:

spring:
  datasource:
    hikari:
      schema: my_schema

Comments

5

You can try setting the default schema for the jdbc user.

  1. ALTER USER user_name SET search_path to 'schema'

  2. Did you try this property?

spring.datasource.schema 

http://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html

1 Comment

Thanks for this! I tried this and this works but as much as I possible, I want to set it somewhere in my application (I also don't want to execute sql files for this somewhere).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.