{"id":2369,"date":"2017-06-06T07:56:06","date_gmt":"2017-06-06T07:56:06","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=2369"},"modified":"2017-06-06T08:28:42","modified_gmt":"2017-06-06T08:28:42","slug":"2369-2","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/2369-2\/","title":{"rendered":"Unidirectional and Bidirectional Mapping"},"content":{"rendered":"<p><strong>Unidirectional<\/strong> &#8211;  bidirectional relationship provides navigational access in one direction <\/p>\n<pre>\r\n  Parent -----> Child\r\n<\/pre>\n<p>i.e you can go from parent to child, but you cannot go back from children to parent.<\/p>\n<p>However, if there were no pointer to Parent in Child:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nclass Child { }\r\n<\/pre>\n<p><strong>Bidirectional<\/strong> &#8211; bidirectional relationship provides navigational access in both directions<\/p>\n<pre>\r\n  Parent <-----> Child\r\n<\/pre>\n<p>i.e you can go from a Parent to its child, and vice-versa: the parent knows about its child, the child knows about its parent<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nclass Parent {\r\n  Child* children;\r\n}\r\n\r\nclass Child {\r\n  Parent* parent;\r\n}\r\n<\/pre>\n<p><strong>Idle Scenarios<\/strong><br \/>\n<strong>One to One unidirectional Mapping<\/strong><br \/>\nemployee knows the employer<\/p>\n<p><strong>One to One Bidirectional Mapping<\/strong><br \/>\nemployer knows the employee and employee knows the employer<\/p>\n<p><strong>One to Many unidirectional Mapping<\/strong><br \/>\nemployee has a skill in his skill set which is not used by other employees <\/p>\n<p><strong>One to Many bidirectional Mapping<\/strong><br \/>\nemployee has a skill in his skill set which is not used by other employees and<br \/>\nemployer knows that employee has this skill in skill set<\/p>\n<p><strong>Many to One unidirectional Mapping<\/strong><br \/>\nemployees knows which employer he is going to work but employer has no idea about employee<\/p>\n<p><em>employees will have employerId in their entity class but employer has no details of employee<\/em><\/p>\n<p><strong>Many to One bidirectional Mapping<\/strong><br \/>\nMany employees work for one Employer. The employer knows about employee and employee knows about employer<\/p>\n<p><em>employees will have employerId in their entity class but employer will have empid of employee<\/em><\/p>\n<p><strong>Many to Many unidirectional Mapping<\/strong><br \/>\nEmployee knows the employers he has worked for but employers does not know details of employee who worked for them<\/p>\n<p><strong>Many to Many bidirectional Mapping<\/strong><br \/>\nEmployee knows about the  employers he has worked for and employers knows about employee who has worked for them. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unidirectional &#8211; bidirectional relationship provides navigational access in one direction Parent &#8212;&#8211;> Child i.e you can go from parent to child, but you cannot go back from children to parent. However, if there were no pointer to Parent in Child: class Child { } Bidirectional &#8211; bidirectional relationship provides navigational access in both directions Parent&hellip; <a href=\"https:\/\/codethataint.com\/blog\/2369-2\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[235,230],"tags":[],"class_list":["post-2369","post","type-post","status-publish","format-standard","hentry","category-jpa","category-interview-questions-database-2"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2369","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=2369"}],"version-history":[{"count":6,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2369\/revisions"}],"predecessor-version":[{"id":2375,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2369\/revisions\/2375"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=2369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=2369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=2369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}