Buddhi Prabhath
1 min readFeb 21, 2020

--

in this case A, B in a cyclic relationship, i would prefer to avoid this

I would prefer not to define the relationships in the Models, in Models i would use relationship using foreign key id, and use @Query to define custom query and fetch the data in jpa repository and

then copy the Model data to Dto’s in service method

in that way we can fetch the parent and child objects separately and set to Dto’s

example:

  1. tables

table_a: id, name

table_b: id, name, table_a_id

2. Models

class A: id, name

class B: id, name, table_a_id

3. Dtos

class A_Dto: id, name, List<B>

class B_Dto: id, name, A

hope this helps

--

--

Buddhi Prabhath
Buddhi Prabhath

No responses yet