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

📄 persistent-classes.html

📁 关于hibernate的中文文档 关于hibernate的中文文档 关于hibernate的中文文档 关于hibernate的中文文档
💻 HTML
📖 第 1 页 / 共 3 页
字号:
            column="ADDRESS"            type="string"/&gt;        &lt;many-to-one name="organization"            column="ORGANIZATION_ID"            class="Organization"/&gt;        &lt;bag name="orders"            inverse="true"            lazy="false"            cascade="all"&gt;            &lt;key column="CUSTOMER_ID"/&gt;            &lt;one-to-many class="Order"/&gt;        &lt;/bag&gt;    &lt;/class&gt;    &lt;/hibernate-mapping&gt;</pre><p>						&#27880;&#24847;&#65292;&#34429;&#28982;&#26159;&#29992;&#30446;&#26631;&#31867;&#21517;&#26469;&#22768;&#26126;&#20851;&#32852;&#30340;&#65292;&#20294;&#26159;&#20851;&#32852;&#30340;&#30446;&#26631;&#31867;&#22411;&#38500;&#20102;&#26159;POJO&#20043;&#22806;&#65292;&#20063;&#21487;&#20197;						&#26159;&#19968;&#20010;&#21160;&#24577;&#30340;&#23454;&#20307;&#12290;				</p><p>						&#22312;&#20351;&#29992;<tt class="literal">dynamic-map</tt>&#20026;<tt class="literal">SessionFactory</tt>						&#35774;&#32622;&#20102;&#40664;&#35748;&#30340;&#23454;&#20307;&#27169;&#24335;&#20043;&#21518;&#65292;&#21487;&#20197;&#22312;&#36816;&#34892;&#26399;&#20351;&#29992;<tt class="literal">Map</tt>&#30340;						<tt class="literal">Map</tt>&#12290;				</p><pre class="programlisting">Session s = openSession();Transaction tx = s.beginTransaction();Session s = openSession();// Create a customerMap david = new HashMap();david.put("name", "David");// Create an organizationMap foobar = new HashMap();foobar.put("name", "Foobar Inc.");// Link bothdavid.put("organization", foobar);// Save boths.save("Customer", david);s.save("Organization", foobar);tx.commit();s.close();</pre><p>						&#21160;&#24577;&#26144;&#23556;&#30340;&#22909;&#22788;&#26159;&#65292;&#21464;&#21270;&#25152;&#38656;&#35201;&#30340;&#26102;&#38388;&#23569;&#20102;&#65292;&#22240;&#20026;&#21407;&#22411;&#19981;&#38656;&#35201;&#23454;&#29616;&#23454;&#20307;&#31867;&#12290;&#28982;&#32780;&#65292;&#20320;&#26080;&#27861;&#36827;&#34892;						&#32534;&#35793;&#26399;&#30340;&#31867;&#22411;&#26816;&#26597;&#65292;&#24182;&#21487;&#33021;&#30001;&#27492;&#20250;&#22788;&#29702;&#24456;&#22810;&#30340;&#36816;&#34892;&#26399;&#24322;&#24120;&#12290;&#24184;&#20111;&#26377;&#20102;Hibernate&#26144;&#23556;&#65292;&#23427;&#20351;&#24471;&#25968;						&#25454;&#24211;&#30340;schema&#33021;&#23481;&#26131;&#30340;&#35268;&#26684;&#21270;&#21644;&#21512;&#29702;&#21270;&#65292;&#24182;&#20801;&#35768;&#31245;&#21518;&#22312;&#27492;&#20043;&#19978;&#28155;&#21152;&#21512;&#36866;&#30340;&#39046;&#22495;&#27169;&#22411;&#23454;&#29616;&#12290;				</p><p>						&#23454;&#20307;&#34920;&#31034;&#27169;&#24335;&#20063;&#33021;&#22312;&#27599;&#20010;<tt class="literal">Session</tt>&#30340;&#22522;&#30784;&#19978;&#35774;&#32622;&#65306;				</p><pre class="programlisting">Session dynamicSession = pojoSession.getSession(EntityMode.MAP);// Create a customerMap david = new HashMap();david.put("name", "David");dynamicSession.save("Customer", david);...dynamicSession.flush();dynamicSession.close()...// Continue on pojoSession</pre><p>						&#35831;&#27880;&#24847;&#65292;&#29992;<tt class="literal">EntityMode</tt>&#35843;&#29992;<tt class="literal">getSession()</tt>&#26159;&#22312;						<tt class="literal">Session</tt>&#30340;API&#20013;&#65292;&#32780;&#19981;&#26159;<tt class="literal">SessionFactory</tt>&#12290;						&#36825;&#26679;&#65292;&#26032;&#30340;<tt class="literal">Session</tt>&#20849;&#20139;&#24213;&#23618;&#30340;JDBC&#36830;&#25509;&#65292;&#20107;&#21153;&#65292;&#21644;&#20854;&#20182;&#30340;&#19978;&#19979;&#25991;&#20449;						&#24687;&#12290;&#36825;&#24847;&#21619;&#30528;&#65292;&#20320;&#19981;&#38656;&#35201;&#22312;&#31532;&#20108;&#20010;<tt class="literal">Session</tt>&#20013;&#35843;&#29992;						<tt class="literal">flush()</tt>&#21644;<tt class="literal">close()</tt>&#65292;&#21516;&#26679;&#30340;&#65292;&#25226;&#20107;&#21153;&#21644;&#36830;&#25509;&#30340;&#22788;&#29702;						&#20132;&#32473;&#21407;&#26469;&#30340;&#24037;&#20316;&#21333;&#20803;&#12290;				</p><p>						&#20851;&#20110;XML&#34920;&#31034;&#33021;&#21147;&#30340;&#26356;&#22810;&#20449;&#24687;&#21487;&#20197;&#22312;<a href="xml.html" title="&#31532;&nbsp;18&nbsp;&#31456;&nbsp;XML&#26144;&#23556;">&#31532;&nbsp;18&nbsp;&#31456; <i>XML&#26144;&#23556;</i></a>&#20013;&#25214;&#21040;&#12290;				</p></div><div class="sect1" lang="zh-cn"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="persistent-classes-tuplizers"></a>4.5.&nbsp;&#20803;&#32452;&#29255;&#26029;&#26144;&#23556;(Tuplizers)</h2></div></div><div></div></div><p>            <tt class="literal">org.hibernate.tuple.Tuplizer</tt>&#65292;&#20197;&#21450;&#20854;&#23376;&#25509;&#21475;&#65292;&#36127;&#36131;&#26681;&#25454;&#32473;&#23450;&#30340;<tt class="literal">org.hibernate.EntityMode</tt>&#65292;&#26469;&#22797;&#29616;&#29255;&#26029;&#25968;&#25454;&#12290;&#22914;&#26524;&#32473;&#23450;&#30340;&#29255;&#26029;&#25968;&#25454;&#34987;&#35748;&#20026;&#20854;&#26159;&#19968;&#31181;&#25968;&#25454;&#32467;&#26500;&#65292;"tuplizer"&#23601;&#26159;&#19968;&#20010;&#30693;&#36947;&#22914;&#20309;&#21019;&#24314;&#36825;&#26679;&#30340;&#25968;&#25454;&#32467;&#26500;&#65292;&#20197;&#21450;&#22914;&#20309;&#32473;&#36825;&#20010;&#25968;&#25454;&#32467;&#26500;&#36171;&#20540;&#30340;&#19996;&#35199;&#12290;&#27604;&#22914;&#35828;&#65292;&#23545;&#20110;POJO&#36825;&#31181;Entity Mode&#65292;&#23545;&#24212;&#30340;tuplizer&#30693;&#36947;&#36890;&#36807;&#20854;&#26500;&#36896;&#26041;&#27861;&#26469;&#21019;&#24314;&#19968;&#20010;POJO&#65292;&#20877;&#36890;&#36807;&#20854;&#23646;&#24615;&#35775;&#38382;&#22120;&#26469;&#35775;&#38382;POJO&#23646;&#24615;&#12290;&#26377;&#20004;&#22823;&#31867;&#39640;&#23618;Tuplizer&#65292;&#20998;&#21035;&#26159;<tt class="literal">org.hibernate.tuple.EntityTuplizer</tt> &#21644;<tt class="literal">org.hibernate.tuple.ComponentTuplizer</tt>&#25509;&#21475;&#12290;<tt class="literal">EntityTuplizer</tt>&#36127;&#36131;&#31649;&#29702;&#19978;&#38754;&#25552;&#21040;&#30340;&#23454;&#20307;&#30340;&#22865;&#32422;&#65292;&#32780;<tt class="literal">ComponentTuplizer</tt>&#21017;&#26159;&#38024;&#23545;&#32452;&#20214;&#30340;&#12290;        </p><p>            &#29992;&#25143;&#20063;&#21487;&#20197;&#25554;&#20837;&#20854;&#33258;&#23450;&#20041;&#30340;tuplizer&#12290;&#25110;&#35768;&#24744;&#38656;&#35201;&#19968;&#31181;&#19981;&#21516;&#20110;dynamic-map entity-mode&#20013;&#20351;&#29992;&#30340;<tt class="literal">java.util.HashMap</tt>&#30340;<tt class="literal">java.util.Map</tt>&#23454;&#29616;&#65307;&#25110;&#35768;&#24744;&#38656;&#35201;&#19982;&#40664;&#35748;&#31574;&#30053;&#19981;&#21516;&#30340;&#20195;&#29702;&#29983;&#25104;&#31574;&#30053;(proxy generation strategy)&#12290;&#36890;&#36807;&#33258;&#23450;&#20041;tuplizer&#23454;&#29616;&#65292;&#36825;&#20004;&#20010;&#30446;&#26631;&#24744;&#37117;&#21487;&#20197;&#36798;&#21040;&#12290;Tuplizer&#23450;&#20041;&#34987;&#38468;&#21152;&#21040;&#23427;&#20204;&#26399;&#26395;&#31649;&#29702;&#30340;entity&#25110;&#32773;component&#26144;&#23556;&#20013;&#12290;&#22238;&#21040;&#25105;&#20204;&#30340;customer entity&#20363;&#23376;&#65306;        </p><pre class="programlisting">&lt;hibernate-mapping&gt;    &lt;class entity-name="Customer"&gt;        &lt;!--            Override the dynamic-map entity-mode            tuplizer for the customer entity        --&gt;        &lt;tuplizer entity-mode="dynamic-map"                class="CustomMapTuplizerImpl"/&gt;        &lt;id name="id" type="long" column="ID"&gt;            &lt;generator class="sequence"/&gt;        &lt;/id&gt;        &lt;!-- other properties --&gt;        ...    &lt;/class&gt;&lt;/hibernate-mapping&gt;public class CustomMapTuplizerImpl        extends org.hibernate.tuple.DynamicMapEntityTuplizer {    // override the buildInstantiator() method to plug in our custom map...    protected final Instantiator buildInstantiator(            org.hibernate.mapping.PersistentClass mappingInfo) {        return new CustomMapInstantiator( mappingInfo );    }    private static final class CustomMapInstantiator            extends org.hibernate.tuple.DynamicMapInstantitor {        // override the generateMap() method to return our custom map...	    protected final Map generateMap() {		    return new CustomMap();	    }    }}</pre></div><p>    		TODO&#65306;property&#21644;proxy&#21253;&#37324;&#30340;&#29992;&#25143;&#25193;&#23637;&#26694;&#26550;&#25991;&#26723;&#12290;    </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="session-configuration.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="mapping.html">&#19979;&#19968;&#39029;</a></td></tr><tr><td width="40%" align="left" valign="top">&#31532;&nbsp;3&nbsp;&#31456;&nbsp;        &#37197;&#32622;    &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;5&nbsp;&#31456;&nbsp;&#23545;&#35937;/&#20851;&#31995;&#25968;&#25454;&#24211;&#26144;&#23556;&#22522;&#30784;(Basic O/R Mapping)</td></tr></table></div></body></html>

⌨️ 快捷键说明

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