Update using Spring data JPA - spring

I am working on updating DB using Spring data JPA. I have update two tables simultaneously.
I was thinking about writing a query based on criteria and update but not sure how I would jot it down. Is there a better way to do it ? if so any tutorial link for that will be helpful.

Related

What is the best way to maintain queries in Spring boot application?

In My Application, Using the below technologies
Spring boot 2.7.x
Cassandra
spring batch 5. x
java 11
As part of this, I need to extract data from the Cassandra database and need to write out the file
so here I need to use queries to fetch data so
just want to know what is the best way to maintain all queries at one place so any query changes come in the future, I shouldn't build the app rather just need to modify the query.
Using a repository class is necessary. If you are using JPA i recommend using a repository for each Entity class. With JDBC it is possible to create a single repository which contains all the queries. To access the query methodes i would use a service class. In this way your code is structured well and maintainable for future changes.

Latest by group query using Spring Boot JPA

I am using Spring Boot 2.5.0 for one of my test projects and need to get some data from one of the transaction tables. I need only latest record per group from this table. This problem has a solution given multiple times on SO, one of which is https://stackoverflow.com/a/1313293/841221.
However, I want to implement the same using Spring Boot Data JPA and not using a native query as using a native query would make me lose database independence.
Can someone please help me?

Creating tables on fly with Spring Boot Data JPA

Trying to build application where tables & its fields are managed by master table & creation of tables & its fields happens on demand, on fly based on user data posted to server.
Tried to look over similar question like this but wasnt able to find clue how to execute dynamic queries in DB without creating Repository & Entity in spring boot.
Robert Niestroj is correct when he writes in the comments
If you have dynamic tables JPA is the wrong approach. JPA is for static schema
I guess in theory you could do something where you generate code and possibly restart your ApplicationContext but it is bound to be really painful and you won't benefit from using JPA.
You should look into more dynamic technologies. MyBatis and plain old JdbcTemplate or NamedParameterJdbcTemplate come to my mind.
Possibly with your own abstraction layer on top of it if you have recurring scenarios.

Need CRUD operations for javers

I want to archive restore the javers audit records. So I want ability to delete the records and insert them again.
Does javers repository provide delete/insert API or we use standard JPA techniques to do that ?
I have searched through the API. It has some hallowDelete API which may not serve purpose as of now.
I should have API like javers.deletebyCommitId(Long id) and javers.insertAuditData(javersEntity) etc.
I think you need to konw some data operation framework, like mybatis and hibernate, maybe jpa is more suitaable you.
I suggest you to use mybatis + mapper. they have own quick start, i think that may help you.
mybatis: https://github.com/mybatis/mybatis-3
Mapper: https://github.com/abel533/Mapper

How to read and write data from multiple databases by using spring batch update?

I am working on spring batchupdate ,I search on google I didn't find any solution for my problem.
I have two databases(MySQL,ORALCE) I want to read data from mysql and write into oracle by using batch update .
Your problem is unclear.
You can first read the data from MySQL with one Spring JdbcTemplate object initialized with MySql data source, and then use another JdbcTemplate object, initialized with Oracle data source, to write the data.
If you want to do it in one transaction, you will have to use distributed transactions/XA libraries, such as Atomicos, and Spring distributed transaction manager. See here https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-jta.html for details on Spring integration with distributed transactions libraries.

Resources