How to set up default schema name in JPA configuration?
Don't know of JPA property for this either. But you could just add the Hibernate property (assuming you use Hibernate as provider) as
...
<property name="hibernate.default_schema" value="myschema"/>
...
Hibernate should pick that up
Change database schema used by Spring Boot
Use for application.properties
:
spring.jpa.properties.hibernate.default_schema=your_scheme
OR for application.yaml
:
spring:
jpa:
properties:
hibernate.default_schema: your_scheme
From the Spring Boot reference guide:
all properties in
spring.jpa.properties.*
are passed through as normal JPA properties (with the prefix stripped) when the localEntityManagerFactory
is created
See http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-configure-jpa-properties
For a full list of available properties see http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-configure-jpa-properties
Hibernate default schema and Table annotation
After a year now app evolved and I am using Spring Boot 1.5.4
and Hibernate 5.1.5
with Postgres 9.6
. Not sure if there were issues with previous versions but now it works fine.
yaml
configuration file:
spring:
datasource:
driver-class-name: org.postgresql.Driver
platform: postgresql
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQL94Dialect
default_schema: SCHEMA_NAME
Although using 9.6, PostgreSQL94Dialect can be used for 9.4 and later as there is no specific PostgreSQL96Dialect for given Hibernate version.
With this there is no need to specify schema in @Table
annotation.
Update October 2018
See Hibernate's repository for supported dialects and set git tag to your Hibernate version: https://github.com/hibernate/hibernate-orm/tree/master/hibernate-core/src/main/java/org/hibernate/dialect
Spring JPA: Providing Schema Name Dynamically
If you need to change the schema name at the runtime, I recommend to use Hibernate multi-tenancy approach. You could find more details here and here
Related Topics
Why I'm Not Able to Unwrap and Serialize a Java Map Using the Jackson Java Library
How to Get a List of Trusted Root Certificates in Java
Absolute Minimum Code to Get a Valid Oauth_Signature Populated in Java or Groovy
How to Upper Case Every First Letter of Word in a String
How Java Do the String Concatenation Using "+"
Check Is a Point (X,Y) Is Between Two Points Drawn on a Straight Line
Self Signed X509 Certificate with Bouncy Castle in Java
Spring 3 MVC: One-To-Many Within a Dynamic Form (Add/Remove on Create/Update)
How to Save Parsed and Changed Dom Document in Xml File
How to Write an Array to a File Java
Mocking Time in Java 8's Java.Time API
Does the Preparedstatement Avoid SQL Injection
Performance Difference Between Java 8 Lambdas and Anonymous Inner Classes
How Pause and Then Resume a Thread
Tomcat Server Fails to Start the Server and Application in Sts