How can two unrelated entities , nothing in common be loaded in one Query using spring data jpa?
Current Code :
User user = userRepo.findOne(userId);
Post post = postRepo.findOne(postId);
This creates two sql query is there any way to do it 1 Query.
Is there any way doing like this
Object[] userAndPost = someRepo.findUserAndPost(userId, postId);
Please note both user and post are unrelated and have no common column on which join can be done.
Sandeep
You could refer to this answer and this post for a better explanation.
I have very little experience, but I've tested this code and it works for your particular case.
In the repo file (I'm using Spring boot):
And then, to test if that worked, you could try this code: