මචන්ලා.. ලොකු උදව්වක් ඕනේ.. HATEOAS එක්ක REST හදද්දී bidirectional relationships manage කරල relation links generate කරගන්න හැටි ගැන පොඩි advice වගයක් ඕනේ.. 
example එකක් විදිහට මේ classes දෙකට bi-direction තියෙනවා කියල හිතුවොත්
මම entity class දෙක ලිව්වේ මෙහෙමයි..
එතකොට මම JSON response එකේ relationship links generate කරද්දී මේ ක්රම දෙකෙන් මොකක්ද කරන්න ඕනේ..?
1 වෙනි ක්රමය කරනවානම් StudentController class එකේ වෙනම method එකක් (GET) ලියන්න වෙනවා නේද අදාළ student ට අදාළ batch එක ගන්න?
2 වෙනි ක්රමයේදී එහෙම ඕනේ වෙන්නේ නෑ නේද? හැබැයි එහෙම කරලා පස්සට maintain කරද්දී තව තව ප්රශ්න එයිද?
Student Response - Method 1
Student Response - Method 2
මෙතැනදී batch එක පැත්තෙන් ගත්තොත් එවන්න වෙන්නේ Resource Collection එකක් නෙහ්..(studentList) ? එතකොට අර විදිහට කරන්න බෑ නේද නිකන් student collection url එක එව්වොත් අදාළ batch එකට filter වෙන්නේ නැති නිසා..
Batch Response
දන්නා කස්ටියගෙන් උදාව්....


example එකක් විදිහට මේ classes දෙකට bi-direction තියෙනවා කියල හිතුවොත්
Student <-----> Batch
Many To One
Many To One
මම entity class දෙක ලිව්වේ මෙහෙමයි..
PHP:
class Student {
Long id;
@ManyToOne
Batch batch;
}
PHP:
class Batch {
Long id;
@OneToMany
List<Student> students;
}
එතකොට මම JSON response එකේ relationship links generate කරද්දී මේ ක්රම දෙකෙන් මොකක්ද කරන්න ඕනේ..?
1 වෙනි ක්රමය කරනවානම් StudentController class එකේ වෙනම method එකක් (GET) ලියන්න වෙනවා නේද අදාළ student ට අදාළ batch එක ගන්න?

2 වෙනි ක්රමයේදී එහෙම ඕනේ වෙන්නේ නෑ නේද? හැබැයි එහෙම කරලා පස්සට maintain කරද්දී තව තව ප්රශ්න එයිද?

Student Response - Method 1
PHP:
"id": "1",
"links": [
{
"rel": "self",
"href": "http://localhost:8080/students/1"
},
{
"rel": "batch",
"href": "http://localhost:8080/students/1/batches/1"
}
]
Student Response - Method 2
PHP:
"id": "1",
"links": [
{
"rel": "self",
"href": "http://localhost:8080/students/1"
},
{
"rel": "batch",
"href": "http://localhost:8080/batches/1"
}
]
මෙතැනදී batch එක පැත්තෙන් ගත්තොත් එවන්න වෙන්නේ Resource Collection එකක් නෙහ්..(studentList) ? එතකොට අර විදිහට කරන්න බෑ නේද නිකන් student collection url එක එව්වොත් අදාළ batch එකට filter වෙන්නේ නැති නිසා..

Batch Response
PHP:
"id": "1",
"links": [
{
"rel": "self",
"href": "http://localhost:8080/batches/1"
},
{
"rel": "student",
"href": "http://localhost:8080/batches/1/students"
}
]
දන්නා කස්ටියගෙන් උදාව්....





