Situation : (Using springs) I have a repository with two methods defined with custom queries
@Query("-----")
public Object getA();
@Query("-----")
public List<Object> getB();
For some reason I don't want to write a join query to retrieve the data,
In the controller I define an end point and in that I can call those methods for which I am able to retrieve the data,
But I would want something like this,
All objects of B should be inside the A Object.
A(Object)
a1:
a2:
a3:
B[3] :
b1:
b2:
b3
How can I do this?
@Serviceis for. Second, ifAhas a relation toB, you should be using@JoinTableon a field ofA, which would mean that fetchingA(@Query("select a from A a")) would give you access to the associatedBs.FetchType.LAZYis used and your additional entities should not be fetched in their entirety. You also have the option of defining multiple mapped@Entitys for the same table, so one with all ofAs fields and then onlyB. This is redundant and in most situations not a best practice, but maybe your use-case is one of these edge cases where it is acceptable (but probably not).