I need a concept to design a multi database application using Spring boot, Hibernate and JPA.
for now i am thinking to support 4 relational database (Mysql, H2, SQLLite, Oracle).
what i am doing is to select the right database profile using the spring boot profile feature and then loading the related database properties.
## application-h2.properties
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url=jdbc:h2:file:~/test
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.h2.console.enabled=true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.H2Dialect
# application-mysql.properties
# MySQL-Database
#spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/ntk?autoReconnect=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
and then in application.properties
spring.profiles.active=h2
Here the the application will run and load the property for h2 database .Same way we can select profile as Mysql and it will load the Mysql related properties.
Here, mostly every query is being generated by JPA based on the dialect. Which is compatible with all the databases (because, at a time we are running this application for one database based on the profile selected).But, my concern is if some complex query that need to be written manually how i can make it compatible for other database. Lets say some query designed for Mysql might not be compatible with Oracle.
Can anyone suggest some approach based on the description given by me , please do let me know if some other information is required.
SELECT MD5(..)and you need it for SQL Server (MSSQL) it would beSELECT HASHBYTES('md5', ..)this is a easy source-to-source conversion, for harder things you also have to write a interpreter in PHP or SQL to handle the more complex cases which a other RDMS might support..