How to make Spring Data JPA work with multiple database vendors? - jpa

I'd like to make my application powered by Spring Data JPA transparently compatible with both MSSQL and Oracle. My application contains a few pieces of native SQL queries and ideally I'd like to organize this as the usual common Spring Data repository XXXRepository with vendor-independent JPQL queries and a couple of extensions as the vendor-specific Spring Data repositories like XXXOracleRepository/XXXMSSQLRepository with vendor-specific native queries.
Is it possible ?

Related

Is there a way for implementing database migrations on Spring JPA without the use of frameworks (e.g.: flyway, liquidbase, etc)?

I'm migrating a system that used to be written in Jdbc Templates to Spring Data JPA. Before, we used to write the SQL queries ourselves, but now that we're modernizing our system, we're going to use Spring Data JPA for this. Due to restrictive factors, i can't implement a database migration framework, such as flyway and liquidbase. Is there any way i can implement those using what i have on Spring JPA?

How to run jpql queries in a console in Spring Data project?

I'm new to Spring Data and trying to learn to projections and DTOs.
If you run a plain Hibernate or JPA project in Idea, there is an access to jpql tool window like View -> Tool Windows -> Persistence.
But when open a Spring Data project in idea the feature is unavailable.
Could i run and debug hql|jpql queries for my DTOs in Idea for Spring Data?
Which is the best tool to debug|run complex jpql queries like joins etc.?
Should i consider another ide or a tool?
Where is a good source of working examples for projections and jpql?

Benefits of using QueryDSL vs. Spring Data?

Im thinking about using QueryDSL in my project where I am already using Spring Data. I am programming a microservice inclidung a REST-Interface.
What are the main differences between Spring Data and QueryDSL? What are the big benefits of using QueryDSL instead of Spring Data?
Querydsl and Spring Data go along well. While both deal with the domain of persistence they have very different goals.
Querydsl provides a type-safe query API.
Spring Data provides a consistent API to accessing persistent stores, inspired by the ideas of Domain Driven Design, without getting in the way of the user and how she wants to formulate queries.
Therefore there exists an extension point to combine Spring Data and Querydsl and you can always implement non-standard queries using Querydsl if they go beyond, what can be easily formulated using the build in Spring Data repositories.

Database Crawler using JPA

We have a requirement for building a database crawler. The application parses the tnsnames, connects to each database and retrieves some information like version, accounts, etc. We are trying to use JPA across the other parts of the application and to persist this data into the application's database.
So far, I only see creating an EntityManagerFactory programmatically for every database. Is there any other options?
We are using Spring, are there any benefits that Spring brings to the table in this scenario?
Thanks
JPA is clearly not the right tool for this job. JPA allows creating functional entities mapping a well-know database schema. Your tool doesn't know anything about the schemas and tables it will find. There could be 0 tables or 5000, with completely unknow names.
You need a much lower-level API to do what you want, like JDBC.
You could use JPA to store the results of your crawlings in a single schema, though.

Paging in each JPA provider for multiple databases

We have many JPA provider such as : OpenJPA, Hibernate, Toplink, EclipseLink... With Hibernate it uses Dialect to implement pagination data. How other providers implement this paging feature for multiple databases if not using Dialect as Hibernate?
DataNucleus JPA implements paging using features of the datastore where available ... HSQL, Derby, Postgresql etc have LIMIT/OFFSET keywords. Oracle, DB2, MSSQL have ROWCURSOR-style keywords.
Hibernate does the exact same thing AFAIK