0

I have this in my application.properties:

spring.jpa.properties.hibernate.default_schema=dbo

However, I sometimes need to disable this, since I have the same entities in two different database servers. One of them requires the schema to be present, the other one requires the schema to not be present.

Is there a way to programmatically disable or override some of the properties in application.properties? I'd like to keep the other properties, i.e. I'd not want to specify everything programmatically, just this one.

levant pied
  • 3,886
  • 5
  • 37
  • 56
  • can you pass this while invoking? Like while calling `java -jar --spring.jpa.properties.hibernate.default_schema=dbo` – aksappy Jan 06 '20 at 19:45
  • Possible duplicate of https://stackoverflow.com/questions/23563363/how-to-override-application-properties-during-production-in-spring-boot – aksappy Jan 06 '20 at 19:46
  • I don't think it would be a good idea to change the setting in the code on the fly. Possibly you have to configure multiple database connections or pass a command line flag or use different profiles. Maybe you can elaborate a bit more. – ced-b Jan 06 '20 at 19:52
  • You can override spring properties on serveral levels. See https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config – FredvN Jan 06 '20 at 20:07
  • @aksappy That's a potential solution, but doesn't allow for validation. E.g. you could still supply the schema when you should not (and programmatic validation would get rid of that issue). – levant pied Jan 06 '20 at 21:03
  • @ced-b Added a clarification. Let me know if I should provide more info. – levant pied Jan 06 '20 at 21:04
  • You should use `multi-tenancy` so that you can switch datasources based on what you want to do dynamically. – Jonathan JOhx Jan 06 '20 at 23:02
  • @Oneguy Can you clarify how switching data sources can drive the default hibernate schema? – levant pied Jan 07 '20 at 20:43
  • @levantpied need to create a couple of classes for supporting multi-tenancy and one of them should implement CurrentTenantIdentifierResolver so that you can five the schema to change. – Jonathan JOhx Jan 07 '20 at 20:58

0 Answers0