{"id":151573,"date":"2019-07-24T17:19:50","date_gmt":"2019-07-24T09:19:50","guid":{"rendered":"http:\/\/vladmihalcea.com\/?p=5925#comment-54661"},"modified":"2019-07-24T17:19:50","modified_gmt":"2019-07-24T09:19:50","slug":"by-henry","status":"publish","type":"post","link":"https:\/\/itteacheritfreelance.hk\/test\/wordpress\/2019\/07\/24\/by-henry\/","title":{"rendered":"By: Henry"},"content":{"rendered":"<p>Hi Vlad, thanks for your blogs on JPA and Hibernate.<\/p>\n<p>In my codebase, I found a <code>Student<\/code> and <code>Course<\/code> entity <a href=\"http:\/\/itteacheritfreelance.hk\/index.php\" title=\"\u672c\u7db1\u9801\u63d0\u4f9b\u4e00\u500b\u65b9\u4fbf\u7684\u5e73\u53f0, \u70ba\u5927\u5bb6\u914d\u5c0d\u96fb\u8166\u88dc\u7fd2,IT freelance, \u79c1\u4eba\u8001\u5e2b , PHP\u88dc\u7fd2, HTML\u88dc\u7fd2, CSS\u88dc\u7fd2, JavaScript\u88dc\u7fd2, XML, Java\u88dc\u7fd2,Server\u88dc\u7fd2, MySQL\u88dc\u7fd2, \u4e2d\u5b78\u96fb\u8166\u79d1\u79c1\u4eba\u88dc\u7fd2, \u5728\u8077\u4eba\u58eb\u96fb\u8166\u63d0\u5347\u88dc\u7fd2,\u5c08\u696d\u8003\u8a66\u96fb\u8166 \u88dc\u7fd2,\u96fb\u8166\u5716\u50cf\u8a2d\u8a08\u96fb\u8166\u88dc\u7fd2, gra\">class<\/a>es with the below relationships.<\/p>\n<p>The <code>Student<\/code> Entity:<\/p>\n<pre class=\"brush: java; title: ; notranslate\">\n@OneToMany(cascade = CascadeType.ALL,\n      fetch = FetchType.LAZY,\n      mappedBy = &quot;student&quot;)\nprivate List courseList = new ArrayList&lt;&gt;();\n<\/pre>\n<p>And the <code>Course<\/code> entity:<\/p>\n<pre class=\"brush: java; title: ; notranslate\">\n@OneToOne(fetch = FetchType.LAZY)\n@JoinColumn(name = &quot;STUDENT_ID&quot;, nullable = false)\nprivate Student student;\n<\/pre>\n<p>I thought in the <code>Course<\/code> entity, the inverse annotation would be a <code>@ManyToOne<\/code> but I found a <code>@OneToOne<\/code>. Is this possible given your statement in one of your article:<\/p>\n<p>&#8220;The bidirectional association requires the child entity mapping to provide a @ManyToOne annotation, which is responsible for controlling the association.&#8221;<\/p>\n<p>Thanks<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi Vlad, thanks for your blogs on JPA and Hibernate.<\/p>\n<p>In my codebase, I found a &lt;code&gt;Student&lt;\/code&gt; and &lt;code&gt;Course&lt;\/code&gt; entity classes with the below relationships.<\/p>\n<p>The &lt;code&gt;Student&lt;\/code&gt; Entity:<\/p>\n<p>[code lang=&#8221;java&#8221;]<br \/>\n@OneToMany(cascade = CascadeType.ALL,<br \/>\n      fetch = FetchType.LAZY,<br \/>\n      mappedBy = &#8220;student&#8221;)<br \/>\nprivate List courseList = new ArrayList&lt;&gt;();<br \/>\n[\/code]<\/p>\n<p>And the &lt;code&gt;Course&lt;\/code&gt; entity:<\/p>\n<p>[code lang=&#8221;java&#8221;]<br \/>\n@OneToOne(fetch = FetchType.LAZY)<br \/>\n@JoinColumn(name = &#8220;STUDENT_ID&#8221;, nullable = false)<br \/>\nprivate Student student;<br \/>\n[\/code]<\/p>\n<p>I thought in the &lt;code&gt;Course&lt;\/code&gt; entity, the inverse annotation would be a &lt;code&gt;@ManyToOne&lt;\/code&gt; but I found a &lt;code&gt;@OneToOne&lt;\/code&gt;. Is this possible given your statement in one of your article:<\/p>\n<p>&#8220;The bidirectional association requires the child entity mapping to provide a @ManyToOne annotation, which is responsible for controlling the association.&#8221;<\/p>\n<p>Thanks <a href=\"https:\/\/itteacheritfreelance.hk\/test\/wordpress\/2019\/07\/24\/by-henry\/\">\u95b1\u8b80\u5168\u6587 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":691,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"slim_seo":[],"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[2,6,315,7],"tags":[398,402,397,414,413,410,409,407,408,406,399,400,394,318,375,523,558,556,557,560,559,555,561,566,553,554,6339,6340,565,563,564,562,183,184,567,524,232,10,401,396,381,403,412,411,395,405,404,457,454,320,319,316,26,317],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p7prtj-DqJ","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/itteacheritfreelance.hk\/test\/wordpress\/wp-json\/wp\/v2\/posts\/151573"}],"collection":[{"href":"https:\/\/itteacheritfreelance.hk\/test\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itteacheritfreelance.hk\/test\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/test\/wordpress\/wp-json\/wp\/v2\/users\/691"}],"replies":[{"embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/test\/wordpress\/wp-json\/wp\/v2\/comments?post=151573"}],"version-history":[{"count":1,"href":"https:\/\/itteacheritfreelance.hk\/test\/wordpress\/wp-json\/wp\/v2\/posts\/151573\/revisions"}],"predecessor-version":[{"id":151574,"href":"https:\/\/itteacheritfreelance.hk\/test\/wordpress\/wp-json\/wp\/v2\/posts\/151573\/revisions\/151574"}],"wp:attachment":[{"href":"https:\/\/itteacheritfreelance.hk\/test\/wordpress\/wp-json\/wp\/v2\/media?parent=151573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/test\/wordpress\/wp-json\/wp\/v2\/categories?post=151573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/test\/wordpress\/wp-json\/wp\/v2\/tags?post=151573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}