JPA archive two tables in a third one - spring

I have two tables, X and Y. I want to archive them in a third, A. Is there a way in Spring Boot without rewriting code? Currently I have duplicate code.

One can use #Embedded annotation for this

Related

Apply Pagination on two different tables and merge results in spring boot

I'm using Spring Data JPA to expose REST APIs. In my application, there are two types of tables available(current and archival) and structure of the current and archival tables are exactly similar and data will be moved for current table to archival table over the period of time for performance reasons. I'm having repository classes to retrieve the data from current and archival table separately and Pagination is also implemented for repositories.
Now I got a requirement to fetch the eligible records from both tables based on criteria and apply pagination at single shot. Is it possible with Spring Data JPA
You can keep the latest version in both tables and when you search for data you just do a regular search.
Another option would be to create a view over the two tables.
I also think Hibernate Envers was able to do that though I never tried it.

Spring HATEOAS, how to handle conversion links to entities without flooding the DB

I'm using Spring boot 2.3, Spring Data REST, Spring HATEOAS, Hibernate.
Let's think to a simple use case like an user creating an invoice in a web client, or a inventory list for a warehouse. When the user submit the form, could be sent hundreds or rows and these rows can have links to other entities.
In the case of the invoice, for example, each row can have a product reference that will be passed to the sever as a link.
That link is translated by Spring into an entity using Repository. My point is that for every row, a query to get the product runs.
This means that everything will be really slow during insert (n+1 select problem).
Probably I missed somthing in the logic, but I didn't see concrete examples that focus on how to handle a big quantity of translations link -> entity.
Do you have any hint about it?
Is your point about many entities that will be created if linked entities will be returned to server? Hibernate (as well as spring) has lazy loading mechanism - https://blog.ippon.tech/boost-the-performance-of-your-spring-data-jpa-application/, so only necessary entities will be populated. Please, correct me if I miss understand your questions.

What is the default order of findAll in Spring Data JPA?

I am fetching entries from a table using findAll of Spring JPA, and I am using only one of the entries. In one of the environment the returned entries are like A,B,C in that order, but in another environment the order returned is B,A,C
The environments do not differ in a way that it may effect. Both of them have the same table, completely same as each other. The code is the same as well.

Why does Room require you to list out entities?

Just curious if anyone knows why Room requires you to list out each entity. Why can't it automatically find all of your entities with the #Entity annotation?
Since you can have more than a single database in a project, Room needs to know which classes are used by which DB.
By declaring the Entities in the DB class you are actually building a hierarchy that informs the compiler which classes to use to produce the wanted result from the DAO.
In theory, your argument does have a point as in cases of a single DB or where there are multi DB but no overlaps there should not be a problem but to prevent overlaps and for clarity sake, they demand that you declare everything.

jpa specification query method

We are using the Spring Data JPA for database access. Our repositories contain basic query methods. What we want to do now is to use the Specification-Interface (criteria API) combined with complex query methods (like findByName(Specification spec)). The problem is that these two ways block each other out (since there are two where queries now). Is there any way to do this, like telling JPA to combine the two where parts with AND? The reason we want to do this is because some parts of the where query are essential for every query. They should be defined in the name of the query method. The Specification only should contain individual criterias for individual use-cases.
Or is there any other way to solve this?
Currently this is not supported. Please feel free to raise a JIRA issue if you think this would be a worthwhile enhancement.

Resources