Spring Data Repository Populator from CSV - spring

Would Spring Data Repository populator be able to pre load the databases using CSV data or what would be the best way to load CSV data in Spring Boot JPA repositories.

I'd use a CommandLineRunner (assuming you're using Spring Boot)
I've put together a small gist here:
https://gist.github.com/jkupcho/a423bd26509adb08844642ad16e16115

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.

How to configure multiple datasources in Spring Data JDBC?

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.

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.

Can JaVers be integrated with Hibernate?

I've seen you can use JaVers to serialize changes to a database, but I can't find a good example about Spring or Hibernate integration. I would also know if I can change the generated table names and columns.
Thank!
In Javers doc, there is the example you are looking for:
http://javers.org/documentation/spring-integration/#spring-jpa-example
If you are using Spring Boot, examples for JaVers Spring Boot starter for SQL
http://javers.org/documentation/spring-boot-integration/
We recommend using the second option - JaVers Spring Boot starter

Spring JPA PostgreSQL + MongoDB

Starting from the Spring example Accessing MongoDB Data with REST (https://spring.io/guides/gs/accessing-mongodb-data-rest/) I'd like to integrate a PostgreSQL data source and link it to the MongoDB repository.By switching from MongoRepository to JpaRepository and accordingly changing the application.properties file I've been able to pass from MongoDB to PostgreSQL and viceversa, but basically having only one active data source at time.
application.properties when using MongoDB
spring.data.mongodb.port=27017
spring.data.mongodb.uri=mongodb://localhost/
spring.data.mongodb.database=myMongoDB_DB
spring.data.mongodb.repositories.enabled=true
application.properties when using PostgreSQL
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/myPostgreSQL_DB
spring.datasource.username=me
spring.datasource.password=mySuperSecretPassword
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create
Is there a way to configure Spring (with an Annotation-only way) to link two data sources to the same Repository so that when I access my REST web service via HTTP both MongoDB and PostgreSQL are changed in exactly the same way?I googled around and found something about Spring cross-store support (http://docs.spring.io/spring-data/mongodb/docs/1.5.5.RELEASE/reference/html/mongo.cross.store.html) but it uses xml for the application configuration and AspectJ, is there a simpler way to accomplish this?
In this chapter you can find an answer - (Spring-boot manual - Use Spring Data JPA and Mongo repositories)

Resources