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

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?

Related

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.

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

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 ?

Using JPA and JDBC together

In my project, we are upgrading an old J2EE application to Java EE 6.
Since the business logic is quite complex, we want to retain the EJB + DAO code as much as possible. The old code uses plain JDBC for database persistence.
But in our new/upgraded application, we plan to use JPA.
We would like to use JPA for all the read operations on database and use JDBC for the writes (inserts/updates/deletes). Is this possible in the same transaction?
For example:
obtain an Entity Manager reference and read an employee record from the database (employee entity) using entity manager find (or a named query)
convert the entity instance to a POJO
update the POJO
perform some business logic on the POJO (reuse old code as-is)
create a JDBC connection and use a prepared statement to update the employee record in database (reuse old code as-is)
Questions:
If I open 2 separate connections to the database - one from JPA and another from JDBC, will it still be in the same transaction (since app server manages the JTA transaction)?
What are the potential issues with this approach?
Since I am updating the database via JDBC, the entity in persistence context will not be in sync with the database. How to handle caching in such cases?
I looked at the following related threads, but I would like to know more in detail.
Combining JPA and JDBC actions in one transaction
Hibernate and JDBC in one transaction

Java EE using MongoDB without JPA or EJB?

Could someone give me an explanation of if what I'm doing makes sense?
I am currently developing a Java EE application using MVC architecture, and MongoDB as my database. What I have is several entities written as Java objects with custom mapping methods to persist to and from my MongoDB, as well as a separate controller class to perform Database queries and operations. I am able to store these entities in my session with no problem, but I haven't tested this on a larger scale. I've tried annotating my objects as beans, however I received errors.
My typical method of transmitting data is to query my MongoDB, receive the information, map it to a java object, and store it in a session to be accessed by the front end. Is this the proper way to go about this?
Do my entities need to be EJBs? What do I have to gain from making them EJBs? I'm sorry if this question is presented poorly and seems unintelligent. I just want to have a better understanding of the technology I am trying to utilize before further developing. Most of the reading I have done on such topics has been to no avail. If anyone has some clear reading or an explanation that should help me understand what I am asking, it would be most appreciated.
I assume by "EJBs", you are referring to "Entity Beans"? In EJB 3, entity beans are "replaced" by JPA. Think of JPA as a "specification" for ORM frameworks. JPA/ORM are frameworks for mapping Java objects to and from relational databases. You are using MongoDB, which is not a relational database, and hence not that suitable for JPA. So I would say no, there is no need for you to consider JPA. Instead you should consider other frameworks, like Spring Data, which can simplify the task you are doing.
in my opinion you can use EJB3 with mongodb without JPA and entity manager, but you will have Stateless/Singleton/Startup/MDB beans with 0 configuration and with perfect managable backend.

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.