I don't know how to make it clear, and i couldn't think of any good title for this.
Basically, i have a database table which looks like this
ID | name | another_column | ref_id |
---|---|---|---|
1 | name1 | asdasd | same_ref1 |
2 | name2 | zzzzzz | same_ref1 |
3 | name3 | aadas | same_ref2 |
4 | name4 | ppppp | same_ref2 |
I have an entity which maps to this table, lets say, and i can use JpaRepository methods :
public class TestObject {
private int id;
private String name;
private String anotherColumn;
private String refId;
}
Is it possible for me to have another object, lets say ParentObject that is mapped based on ref_id column
public class ParentObject {
private String refId;
private List<TestObject> child;
}
That way when I use a JpaRepository<ParentObject>
for example
parentRepository.findById("same_ref2");
it returns a ParentObject with two children (lines 3 and 4).
Don't know if I made that clear.