I have this table which I would like to store a chain of records.
CREATE TABLE table_name (
id INT,
unique_id varchar,
reference_id varchar,
);
I want to implement JPA query which prints all records by unique_id with all record reference_id. Something like this:
| id | unique_id | reference_id | | |
|----|-----------|--------------|---|---|
| 43 | 55544 | | | |
| 45 | 45454 | 55544 | | |
| 66 | 55655 | 45454 | | |
| 78 | 88877 | 55655 | | |
| 99 | 454 | 34345 | | |
I would like when I select record 55544 to get all transactions because each other are using reference_id which points to them. How I can implement this JPA?
Expected result for record with unique_id 55544:
| id | unique_id | reference_id | | |
|----|-----------|--------------|---|---|
| 43 | 55544 | | | |
| 45 | 45454 | 55544 | | |
| 66 | 55655 | 45454 | | |
| 78 | 88877 | 55655 | | |