⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 associations.html

📁 关于hibernate的中文文档 关于hibernate的中文文档 关于hibernate的中文文档 关于hibernate的中文文档
💻 HTML
📖 第 1 页 / 共 2 页
字号:
        &lt;one-to-many class="Person"/&gt;    &lt;/set&gt;&lt;/class&gt;</pre><pre class="programlisting">create table Person ( personId bigint not null primary key, addressId bigint not null )create table Address ( addressId bigint not null primary key )        </pre><p>            &#22914;&#26524;&#20320;&#20351;&#29992;<tt class="literal">List</tt>(&#25110;&#32773;&#20854;&#20182;&#26377;&#24207;&#38598;&#21512;&#31867;)&#65292;&#20320;&#38656;&#35201;&#35774;&#32622;&#22806;&#38190;&#23545;&#24212;&#30340;<tt class="literal">key</tt>&#21015;&#20026; <tt class="literal">not null</tt>,&#35753;Hibernate&#26469;&#20174;&#38598;&#21512;&#31471;&#31649;&#29702;&#20851;&#32852;&#65292;&#32500;&#25252;&#27599;&#20010;&#20803;&#32032;&#30340;&#32034;&#24341;&#65288;&#36890;&#36807;&#35774;&#32622;<tt class="literal">update="false"</tt> and <tt class="literal">insert="false"</tt>&#26469;&#23545;&#21478;&#19968;&#31471;&#21453;&#21521;&#25805;&#20316;&#65289;&#12290;        </p><pre class="programlisting">&lt;class name="Person"&gt;   &lt;id name="id"/&gt;   ...   &lt;many-to-one name="address"      column="addressId"      not-null="true"      insert="false"      update="false"/&gt;&lt;/class&gt;&lt;class name="Address"&gt;   &lt;id name="id"/&gt;   ...   &lt;list name="people"&gt;      &lt;key column="addressId" not-null="true"/&gt;      &lt;list-index column="peopleIdx"/&gt;      &lt;one-to-many class="Person"/&gt;   &lt;/list&gt;&lt;/class&gt;</pre><p>                &#20551;&#33509;&#38598;&#21512;&#26144;&#23556;&#30340;<tt class="literal">&lt;key&gt;</tt>&#20803;&#32032;&#23545;&#24212;&#30340;&#24213;&#23618;&#22806;&#38190;&#23383;&#27573;&#26159;<tt class="literal">NOT NULL</tt>&#30340;&#65292;&#37027;&#20040;&#20026;&#36825;&#19968;key&#20803;&#32032;&#23450;&#20041;<tt class="literal">not-null="true"</tt>&#26159;&#24456;&#37325;&#35201;&#30340;&#12290;&#19981;&#35201;&#20165;&#20165;&#20026;&#21487;&#33021;&#30340;&#23884;&#22871;<tt class="literal">&lt;column&gt;</tt>&#20803;&#32032;&#23450;&#20041;<tt class="literal">not-null="true"</tt>&#65292;<tt class="literal">&lt;key&gt;</tt>&#20803;&#32032;&#20063;&#26159;&#38656;&#35201;&#30340;&#12290;            </p></div><div class="sect2" lang="zh-cn"><div class="titlepage"><div><div><h3 class="title"><a name="assoc-bidirectional-121"></a>7.4.2.&nbsp;&#19968;&#23545;&#19968;&#65288;one to one&#65289;</h3></div></div><div></div></div><p>           <span class="emphasis"><em>&#22522;&#20110;&#22806;&#38190;&#20851;&#32852;&#30340;&#21452;&#21521;&#19968;&#23545;&#19968;&#20851;&#32852;</em></span>&#20063;&#24456;&#24120;&#35265;&#12290;        </p><pre class="programlisting">&lt;class name="Person"&gt;    &lt;id name="id" column="personId"&gt;        &lt;generator class="native"/&gt;    &lt;/id&gt;    &lt;many-to-one name="address"         column="addressId"         unique="true"        not-null="true"/&gt;&lt;/class&gt;&lt;class name="Address"&gt;    &lt;id name="id" column="addressId"&gt;        &lt;generator class="native"/&gt;    &lt;/id&gt;   &lt;one-to-one name="person"         property-ref="address"/&gt;&lt;/class&gt;</pre><pre class="programlisting">create table Person ( personId bigint not null primary key, addressId bigint not null unique )create table Address ( addressId bigint not null primary key )        </pre><p>            <span class="emphasis"><em>&#22522;&#20110;&#20027;&#38190;&#20851;&#32852;&#30340;&#19968;&#23545;&#19968;&#20851;&#32852;</em></span>&#38656;&#35201;&#20351;&#29992;&#29305;&#23450;&#30340;id&#29983;&#25104;&#22120;&#12290;        </p><pre class="programlisting">&lt;class name="Person"&gt;    &lt;id name="id" column="personId"&gt;        &lt;generator class="native"/&gt;    &lt;/id&gt;    &lt;one-to-one name="address"/&gt;&lt;/class&gt;&lt;class name="Address"&gt;    &lt;id name="id" column="personId"&gt;        &lt;generator class="foreign"&gt;            &lt;param name="property"&gt;person&lt;/param&gt;        &lt;/generator&gt;    &lt;/id&gt;    &lt;one-to-one name="person"         constrained="true"/&gt;&lt;/class&gt;</pre><pre class="programlisting">create table Person ( personId bigint not null primary key )create table Address ( personId bigint not null primary key )        </pre></div></div><div class="sect1" lang="zh-cn"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="assoc-bidirectional-join"></a>7.5.&nbsp;&#20351;&#29992;&#36830;&#25509;&#34920;&#30340;&#21452;&#21521;&#20851;&#32852;&#65288;Bidirectional associations with join tables&#65289;</h2></div></div><div></div></div><div class="sect2" lang="zh-cn"><div class="titlepage"><div><div><h3 class="title"><a name="assoc-bidirectional-join-12m"></a>7.5.1.&nbsp;&#19968;&#23545;&#22810;&#65288;one to many&#65289; /&#22810;&#23545;&#19968;&#65288; many to one&#65289;</h3></div></div><div></div></div><p>             <span class="emphasis"><em>&#22522;&#20110;&#36830;&#25509;&#34920;&#30340;&#21452;&#21521;&#19968;&#23545;&#22810;&#20851;&#32852;</em></span>&#12290;&#27880;&#24847;<tt class="literal">inverse="true"</tt>&#21487;&#20197;&#20986;&#29616;&#22312;&#20851;&#32852;&#30340;&#20219;&#24847;&#19968;&#31471;&#65292;&#21363;collection&#31471;&#25110;&#32773;join&#31471;&#12290;        </p><pre class="programlisting">&lt;class name="Person"&gt;    &lt;id name="id" column="personId"&gt;        &lt;generator class="native"/&gt;    &lt;/id&gt;    &lt;set name="addresses"         table="PersonAddress"&gt;        &lt;key column="personId"/&gt;        &lt;many-to-many column="addressId"            unique="true"            class="Address"/&gt;    &lt;/set&gt;&lt;/class&gt;&lt;class name="Address"&gt;    &lt;id name="id" column="addressId"&gt;        &lt;generator class="native"/&gt;    &lt;/id&gt;    &lt;join table="PersonAddress"         inverse="true"         optional="true"&gt;        &lt;key column="addressId"/&gt;        &lt;many-to-one name="person"            column="personId"            not-null="true"/&gt;    &lt;/join&gt;&lt;/class&gt;</pre><pre class="programlisting">create table Person ( personId bigint not null primary key )create table PersonAddress ( personId bigint not null, addressId bigint not null primary key )create table Address ( addressId bigint not null primary key )        </pre></div><div class="sect2" lang="zh-cn"><div class="titlepage"><div><div><h3 class="title"><a name="assoc-bidirectional-join-121"></a>7.5.2.&nbsp;&#19968;&#23545;&#19968;&#65288;one to one&#65289;</h3></div></div><div></div></div><p>            <span class="emphasis"><em>&#22522;&#20110;&#36830;&#25509;&#34920;&#30340;&#21452;&#21521;&#19968;&#23545;&#19968;&#20851;&#32852;</em></span>&#26497;&#20026;&#32597;&#35265;&#65292;&#20294;&#20063;&#26159;&#21487;&#34892;&#30340;&#12290;        </p><pre class="programlisting">&lt;class name="Person"&gt;    &lt;id name="id" column="personId"&gt;        &lt;generator class="native"/&gt;    &lt;/id&gt;    &lt;join table="PersonAddress"         optional="true"&gt;        &lt;key column="personId"             unique="true"/&gt;        &lt;many-to-one name="address"            column="addressId"             not-null="true"            unique="true"/&gt;    &lt;/join&gt;&lt;/class&gt;&lt;class name="Address"&gt;    &lt;id name="id" column="addressId"&gt;        &lt;generator class="native"/&gt;    &lt;/id&gt;    &lt;join table="PersonAddress"         optional="true"        inverse="true"&gt;        &lt;key column="addressId"             unique="true"/&gt;        &lt;many-to-one name="person"            column="personId"             not-null="true"            unique="true"/&gt;    &lt;/join&gt;&lt;/class&gt;</pre><pre class="programlisting">create table Person ( personId bigint not null primary key )create table PersonAddress ( personId bigint not null primary key, addressId bigint not null unique )create table Address ( addressId bigint not null primary key )        </pre></div><div class="sect2" lang="zh-cn"><div class="titlepage"><div><div><h3 class="title"><a name="assoc-bidirectional-join-m2m"></a>7.5.3.&nbsp;&#22810;&#23545;&#22810;&#65288;many to many&#65289;</h3></div></div><div></div></div><p>            &#26368;&#21518;&#65292;&#36824;&#26377; <span class="emphasis"><em>&#21452;&#21521;&#22810;&#23545;&#22810;&#20851;&#32852;</em></span>.        </p><pre class="programlisting">&lt;class name="Person"&gt;    &lt;id name="id" column="personId"&gt;        &lt;generator class="native"/&gt;    &lt;/id&gt;    &lt;set name="addresses"  table="PersonAddress"&gt;        &lt;key column="personId"/&gt;        &lt;many-to-many column="addressId"            class="Address"/&gt;    &lt;/set&gt;&lt;/class&gt;&lt;class name="Address"&gt;    &lt;id name="id" column="addressId"&gt;        &lt;generator class="native"/&gt;    &lt;/id&gt;    &lt;set name="people" inverse="true"  table="PersonAddress"&gt;        &lt;key column="addressId"/&gt;        &lt;many-to-many column="personId"            class="Person"/&gt;    &lt;/set&gt;&lt;/class&gt;</pre><pre class="programlisting">create table Person ( personId bigint not null primary key )create table PersonAddress ( personId bigint not null, addressId bigint not null, primary key (personId, addressId) )create table Address ( addressId bigint not null primary key )        </pre></div></div><div class="sect1" lang="zh-cn"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="assoc-complex"></a>7.6.&nbsp;&#26356;&#22797;&#26434;&#30340;&#20851;&#32852;&#26144;&#23556;</h2></div></div><div></div></div><p>            &#26356;&#22797;&#26434;&#30340;&#20851;&#32852;&#36830;&#25509;<span class="emphasis"><em>&#26497;&#20026;</em></span>&#32597;&#35265;&#12290;             &#36890;&#36807;&#22312;&#26144;&#23556;&#25991;&#26723;&#20013;&#23884;&#20837;SQL&#29255;&#26029;&#65292;Hibernate&#20063;&#21487;&#20197;&#22788;&#29702;&#26356;&#20026;&#22797;&#26434;&#30340;&#24773;&#20917;&#12290;&#27604;&#22914;&#65292;&#20551;&#33509;&#21253;&#21547;&#21382;&#21490;&#24080;&#25143;&#25968;&#25454;&#30340;&#34920;&#23450;&#20041;&#20102;<tt class="literal">accountNumber</tt>, <tt class="literal">effectiveEndDate</tt> &#21644;<tt class="literal">effectiveStartDate</tt>&#23383;&#27573;&#65292;&#25353;&#29031;&#19979;&#38754;&#26144;&#23556;&#65306;        </p><pre class="programlisting">&lt;properties name="currentAccountKey"&gt;    &lt;property name="accountNumber" type="string" not-null="true"/&gt;    &lt;property name="currentAccount" type="boolean"&gt;        &lt;formula&gt;case when effectiveEndDate is null then 1 else 0 end&lt;/formula&gt;    &lt;/property&gt;&lt;/properties&gt;&lt;property name="effectiveEndDate" type="date"/&gt;&lt;property name="effectiveStateDate" type="date" not-null="true"/&gt;</pre><p>        &#37027;&#20040;&#25105;&#20204;&#21487;&#20197;&#23545;<span class="emphasis"><em>&#30446;&#21069;(current)</em></span>&#23454;&#20363;(&#20854;<tt class="literal">effectiveEndDate</tt>&#20026;null)&#20351;&#29992;&#36825;&#26679;&#30340;&#20851;&#32852;&#26144;&#23556;:        </p><pre class="programlisting">&lt;many-to-one name="currentAccountInfo"         property-ref="currentAccountKey"        class="AccountInfo"&gt;    &lt;column name="accountNumber"/&gt;    &lt;formula&gt;'1'&lt;/formula&gt;&lt;/many-to-one&gt;</pre><p>            &#26356;&#22797;&#26434;&#30340;&#20363;&#23376;,&#20551;&#24819;<tt class="literal">Employee</tt>&#21644;<tt class="literal">Organization</tt>&#20043;&#38388;&#30340;&#20851;&#32852;&#26159;&#36890;&#36807;&#19968;&#20010;<tt class="literal">Employment</tt>&#20013;&#38388;&#34920;&#32500;&#25252;&#30340;,&#32780;&#20013;&#38388;&#34920;&#20013;&#22635;&#20805;&#20102;&#24456;&#22810;&#21382;&#21490;&#38599;&#21592;&#25968;&#25454;&#12290;&#37027;&#8220;&#38599;&#21592;&#30340;<span class="emphasis"><em>&#26368;&#26032;</em></span>&#38599;&#20027;&#8221;&#36825;&#20010;&#20851;&#32852;&#65288;&#26368;&#26032;&#38599;&#20027;&#23601;&#26159;<tt class="literal">startDate</tt>&#26368;&#21518;&#30340;&#37027;&#20010;&#65289;&#21487;&#20197;&#36825;&#26679;&#26144;&#23556;&#65306;        </p><pre class="programlisting">&lt;join&gt;    &lt;key column="employeeId"/&gt;    &lt;subselect&gt;        select employeeId, orgId         from Employments         group by orgId         having startDate = max(startDate)    &lt;/subselect&gt;    &lt;many-to-one name="mostRecentEmployer"             class="Organization"             column="orgId"/&gt;&lt;/join&gt;</pre><p>        &#20351;&#29992;&#36825;&#19968;&#21151;&#33021;&#26102;&#21487;&#20197;&#20805;&#28385;&#21019;&#24847;&#65292;&#20294;&#36890;&#24120;&#26356;&#21152;&#23454;&#29992;&#30340;&#26159;&#29992;HQL&#25110;&#26465;&#20214;&#26597;&#35810;&#26469;&#22788;&#29702;&#36825;&#20123;&#24773;&#24418;&#12290;        </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="collections.html">&#19978;&#19968;&#39029;</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="index.html">&#19978;&#19968;&#32423;</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="components.html">&#19979;&#19968;&#39029;</a></td></tr><tr><td width="40%" align="left" valign="top">&#31532;&nbsp;6&nbsp;&#31456;&nbsp;&#38598;&#21512;&#31867;(Collections)&#26144;&#23556;&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html">&#36215;&#22987;&#39029;</a></td><td width="40%" align="right" valign="top">&nbsp;&#31532;&nbsp;8&nbsp;&#31456;&nbsp;&#32452;&#20214;&#65288;Component&#65289;&#26144;&#23556;</td></tr></table></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -