How to configure multiple datasources in Spring Data JDBC? - spring

I'm trying to replace some projects to use Spring Data JDBC
instead of using JdbcTemplate.
Now, I'd like to use it for multiple DataSources, how can I configure it in Spring Data JDBC?

There is currently no support for working with two or more DataSources. You'd have to manually redo what the JdbcRepositoryFactoryBean does.

Related

Can a single Spring boot/Spring data application have repo of Posgres and MongoDB

I am having a need where in a same spring boot application I need to use repo of Spring Data Mongo and Spring data jpa (postgres), during my initial testing I got runtime errors. While I debug more just wanted to check in same Spring Data Application can it have both repos for Postgres and MongoDB ?
Yes, you can have, make sure to add all dependency and create separate repositories for each data connection. I used MongoDB and MySql database it is working fine.

Create DB tables programmatically using Spring or Hibernate

I'm using Spring Boot 2 and Spring Data JPA using Hibernate 5.2. Spring or Hibernate (not sure, which one does it) can create DB tables automatically by setting spring.jpa.hibernate.ddl-auto = create. This automatically uses the connections settings from spring and the #Entity annotated classes to generate a schema for the DB platform I'm using and creates it.
I want to do the same but in code. I want to add a method that automatically uses existing classes and settings to generate the schema SQL and creates the tables. How to do that?
I tried StandardServiceRegistryBuilder and MetadataSources but I have to configure it manually. I assume there should be a way like Spring is doing it by itself.

custom update and delete queries in spring boot for postgresql

hi I am trying to update and delete the data in my application in spring boot and I came to know that postgresql is quite different from normal SQL can you provide the correct syntax for the update and delete operations in postgresql for spring boot application please I couldn't find it in internet.
If you use Spring Boot you actually could use Spring Data for creating queries and you'll not need to write queries by yourself.

How to configure multiple databases in Hibernate with spring boot application

In my project, there is a requirement to use different databases. We are currently using MySql database with Hibernate as ORM layer. And we are hibernate SessionFactory to query the database.
Now there is a requirement to use SQLite database as well. I have found several examples on the internet but they are all using JdbcTemplate.
https://blog.pranavek.com/using-multiple-datasource-in-spring-boot-application/
https://scattercode.co.uk/2016/01/05/multiple-databases-with-spring-boot-and-spring-data-jpa/
But my requirement is to use separate sessionFactories for both the databases.
Please, help me in receiving that.

Use spring-data-rest without jpa but only JdbcTemplate

Is it possible to use spring-data-rest without spring-data-jpa?
In my application I use JdbcTemplate. Can this be wired to spring-data-rest somehow?
Update from 4 years later:
Meanwhile there is spring-data-jdbc which looks like it answers the original question.
See: https://spring.io/projects/spring-data-jdbc
No, it can't. From the introduction section of the documentation:
Spring Data REST builds on top of Spring Data repositories and automatically exports those as REST resources
If you're using JdbcTemplate for you data access, rather than using Spring Data repositories (be it JPA or any of the other supported back ends) then there is nothing for Spring Data REST to build on and export as REST resources.

Resources