Spring data jpa populate data relationships - spring

I use the spring data jpa framework to easily handle the whole dao stuff and it is awesome. A couple of days ago I test the repo populator functionality of spring data jpa and it also worked pretty smooth, but is it possible to handle relationships ? not the cascade persist types, they are easy to handle ... I mean those one to one relationships where the data for this type is provides by another json file.
Hmm I hope it is a bit understandable what I want to do. Did anyone has an idea to handle this with spring data jpa?
Thanks for any kind of help and have a good weekend :)

Related

Spring Boot Rest API + JPA

I have a CRUD based application, which uses Spring Boot REST Services and JPA. For JPA we have POJO objects mapped to RBMS - PostgreSQL.
Some of my pages require data to be fetched using joins of multiple POJO objects. I just wanted to know what is a good architectural practice to do the same. Following are some of the options i have been informed of, but not sure what are the pros and cons of each especially for a large data volume application.
Use Transient Variables in POJOs and use JPA joins
Use additional Spring View Objects to combine POJOs
Write native/HQL to join tables/POJOs
Any insight would be helpful. If any more details required from me, would be glad to provide.
I think it's better to go with Entity Mappings.
This will enable you to easily fetch the parent and its nested entities using either JPA methods or using hibernate.
You can also specify the fetch type to actually control the behaviour of this fetch.
In case, you are looking for any complex joins or fetch patterns, Entity Graphs and HQL will be very useful.

Looking for a way to improve performance on retrieving a large number of records in spring data jpa

I have an inherited code in where it retrieves a list of person object from a relational database via spring data jpa framework.
There is an interface PersonRepository extends JpaRepository<Person,UUID> in the application. I noticed that findAll method from its parent interface pulls data however due to a large number of records, it takes a quite a while to load it.
I am trying to somehow optimize its poor performance but I don't have much clue at this point. Beside I am new to spring data jpa and have very basic understanding of it.
Is there any good recommendation you could provide for this matter? I greatly appreciate it.
update:
I realized later that the Person entity has multiple #OneToMany relationships with other entities. I noticed lazy loading was turned off. Once I enabled lazy loading #OneToMany(fetchtype.lazy), I noticed a huge delta in its performance.
Use pagination with Pageable.
Look at it: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.core-concepts

How should I define non-entity repositories with Spring Data MongoDB?

On my domain I have the usual entities (User, Company, etc) and also "entities" that doesn't change, I mean they are fixed values but stored on data base. My backend is Mongo so I make use of MongoRepository. I'm also using Spring Data Rest.
Let's say I have defined Sector as entity, which is nothing more than a String wrapped on a Java object.
So this is how I define the repository.
#RepositoryRestResource
public interface SectorRepo extends MongoRepository<Sector,String>{
}
The thing is that this seems to be inappropriate, as I should not define an object that only wraps an string and treat it as an entity, it isn't. The only purpose for Sector collection is to be loaded on a combo box, nothing more.
The problem gets serious when you have more and more of these non-entities objects.
How I should approach this situation so I can still use MongoRepository + Spring Data Rest?
This is similar to couple of other questions. Please see my answers for both. Hope it helps
Spring Data MongoDB eliminate POJO's
Storing a JSON schema in mongodb with spring

Advantages of using Hibernate over Open JPA

I want to use Hibernate in my application(In combination with Spring).
so I would like to know what are the general advantages of using Spring Hibernate over Spring Open JPA?
I have seen many links but did not get the clear idea.
Please let me know.
Here is a performance comparison statistics for a test and the results of the tests per JPA implementation library.
For this test the time was fixed to 30 minutes of running.
The following chart presents results of a specific test(persisting simple entity objects in batches of 5000 per transactions)
Information sources : Soruce 1 , Source 2
Hope this helps.

Does Spring data Neo4j support schema-less property?

The nosql database has schema-less property, so we could add any fields/properties to nodes or relationship. But If I use spring data as the framework, I have to pre-define the field of nodes and relationship object. It seem Spring data Neo4j not support inserting field dynamically...Is it true?
It most definitely supports dynamically inserting fields.
Just update your POJOs with the appropriate fields/annotations, run it, and enjoy the magic!
To recap:
Update your POJOs whenever you need with whatever fields and annotations.
Run your project.
Profit.
If you are using Spring Data Neo4j version 3, then DynamicProperties will probably fulfill your needs.
However, in version 4 it has not yet been implemented see this discussion.

Resources