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

📄 transactions.html

📁 图象处理
💻 HTML
📖 第 1 页 / 共 3 页
字号:
foo.setProperty("bar");session = factory.openSession();session.saveOrUpdate(foo);session.flush();session.connection().commit();session.close();</pre><p>                &#20320;&#20063;&#21487;&#20197;&#35843;&#29992;<tt class="literal">lock()</tt>&#32780;&#38750;<tt class="literal">update()</tt>&#65292;&#22914;&#26524;&#20320;&#30830;&#20449;&#23545;&#35937;&#27809;&#26377;&#34987;&#20462;&#25913;&#36807;&#65292;&#21487;&#20197;&#20351;&#29992;<tt class="literal">LockMode.READ</tt>&#65288;&#36827;&#34892;&#19968;&#27425;&#29256;&#26412;&#26816;&#26597;&#65292;&#32780;&#36339;&#36807;&#25152;&#26377;&#30340;&#32531;&#23384;&#65289;&#12290;            </p></div><div class="sect2" lang="zh-cn"><div class="titlepage"><div><div><h3 class="title"><a name="transactions-optimistic-manual"></a>10.4.3.&nbsp;&#24212;&#29992;&#31243;&#24207;&#33258;&#24049;&#36827;&#34892;&#29256;&#26412;&#26816;&#26597;</h3></div></div><div></div></div><p>	        &#27599;&#24403;&#19968;&#20010;&#26032;&#30340;<tt class="literal">Session</tt>&#20013;&#19982;&#25968;&#25454;&#24211;&#20986;&#29616;&#20132;&#20114;&#30340;&#26102;&#20505;&#65292;&#36825;&#20010;session&#20250;&#22312;&#25805;&#20316;&#25345;&#20037;&#21270;&#23454;&#20363;&#21069;&#37325;&#26032;&#25226;&#23427;&#20204;&#20174;&#25968;&#25454;&#24211;&#20013;&#35013;&#36733;&#36827;&#26469;&#12290;&#25105;&#20204;&#29616;&#22312;&#25152;&#35828;&#30340;&#26041;&#24335;&#23601;&#26159;&#20320;&#30340;&#24212;&#29992;&#31243;&#24207;&#33258;&#24049;&#20351;&#29992;&#29256;&#26412;&#26816;&#26597;&#26469;&#30830;&#20445;&#24212;&#29992;&#20107;&#21153;&#30340;&#38548;&#31163;&#24615;&#12290;&#65288;&#24403;&#28982;&#65292;Hibernate&#20173;&#20250;&#20026;&#20320;<span class="emphasis"><em>&#26356;&#26032;</em></span>&#29256;&#26412;&#21495;&#65289;&#12290;&#20174;&#25968;&#25454;&#24211;&#35775;&#38382;&#26041;&#38754;&#26469;&#30475;&#65292;&#36825;&#31181;&#26041;&#27861;&#26159;&#26368;&#27809;&#26377;&#25928;&#29575;&#30340;&#65292;&#19982;entity EJB&#26041;&#24335;&#31867;&#20284;&#12290;	    </p><pre class="programlisting">// foo is an instance loaded by a previous Sessionsession = factory.openSession();int oldVersion = foo.getVersion();session.load( foo, foo.getKey() );if ( oldVersion!=foo.getVersion ) throw new StaleObjectStateException();foo.setProperty("bar");session.flush();session.connection().commit();session.close();</pre><p>	        &#24403;&#28982;&#65292;&#22914;&#26524;&#22312;&#20302;&#25968;&#25454;&#24182;&#34892;&#65288;low-data-concurrency&#65289;&#30340;&#29615;&#22659;&#20013;&#65292;&#24182;&#19981;&#38656;&#35201;&#29256;&#26412;&#26816;&#26597;&#65292;&#20320;&#20173;&#21487;&#20197;&#20351;&#29992;&#36825;&#20010;&#26041;&#27861;&#65292;&#21482;&#38656;&#35201;&#24573;&#30053;&#29256;&#26412;&#26816;&#26597;&#12290;	    </p></div></div><div class="sect1" lang="zh-cn"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="transactions-disconnection"></a>10.5.&nbsp;&#20250;&#35805;&#26029;&#24320;&#36830;&#25509;&#65288;Session disconnection&#65289;</h2></div></div><div></div></div><p>            The first approach described above is to maintain a single <tt class="literal">Session</tt>             for a whole business process thats spans user think time. (For example, a servlet might             keep a <tt class="literal">Session</tt> in the user's <tt class="literal">HttpSession</tt>.) For             performance reasons you should        </p><p>	    &#19978;&#38754;&#25552;&#21040;&#30340;&#31532;&#19968;&#31181;&#26041;&#27861;&#26159;&#23545;&#20110;&#23545;&#19968;&#20010;&#29992;&#25143;&#30340;&#19968;&#27425;&#30331;&#24405;&#20135;&#29983;&#30340;&#25972;&#20010;&#21830;&#19994;&#36807;&#31243;&#32500;&#25252;&#19968;&#20010;<tt class="literal">Session</tt>&#12290;&#65288;&#20030;&#20363;&#26469;&#35828;&#65292;servlet&#26377;&#21487;&#33021;&#20250;&#22312;&#29992;&#25143;&#30340;<tt class="literal">HttpSession</tt>&#20013;&#20445;&#30041;&#19968;&#20010;<tt class="literal">Session</tt>&#65289;&#12290;&#20026;&#24615;&#33021;&#32771;&#34385;&#65292;&#20320;&#24517;&#39035;	</p><div class="orderedlist"><ol type="1" compact><li><p>		    &#25552;&#20132;<tt class="literal">Transaction</tt>&#65288;&#25110;&#32773;JDBC&#36830;&#25509;&#65289;&#65292;&#28982;&#21518;				</p></li><li><p>		    (&#22312;&#31561;&#24453;&#29992;&#25143;&#25805;&#20316;&#21069;&#65292;)&#26029;&#24320;<tt class="literal">Session</tt>&#19982;JDBC&#36830;&#25509;&#12290;		</p></li></ol></div><p>	    <tt class="literal">Session.disconnect()</tt>&#26041;&#27861;&#20250;&#26029;&#24320;&#20250;&#35805;&#19982;JDBC&#30340;&#36830;&#25509;&#65292;&#25226;&#36830;&#25509;&#36820;&#36824;&#32473;&#36830;&#25509;&#27744;&#65288;&#38500;&#38750;&#26159;&#20320;&#33258;&#24049;&#25552;&#20379;&#36825;&#20010;&#36830;&#25509;&#30340;&#65289;&#12290;	</p><p>	    <tt class="literal">Session.reconnect()</tt>&#26041;&#27861;&#20250;&#24471;&#21040;&#19968;&#20010;&#26032;&#30340;&#36830;&#25509;&#65288;&#20320;&#20063;&#21487;&#20197;&#33258;&#24049;&#25552;&#20379;&#19968;&#20010;&#65289;&#65292;&#37325;&#26032;&#24320;&#22987;&#20250;&#35805;&#12290;&#22312;&#37325;&#26032;&#36830;&#25509;&#21518;&#65292;&#20320;&#21487;&#20197;&#36890;&#36807;&#23545;&#20219;&#20309;&#21487;&#33021;&#34987;&#20854;&#23427;&#20107;&#21153;&#26356;&#26032;&#30340;&#23545;&#35937;&#35843;&#29992;<tt class="literal">Session.lock()</tt>&#26041;&#27861;&#65292;&#26469;&#24378;&#36843;&#23545;&#20320;&#27809;&#26377;&#26356;&#26032;&#30340;&#25968;&#25454;&#36827;&#34892;&#29256;&#26412;&#26816;&#26597;&#12290;&#20320;&#19981;&#38656;&#35201;&#23545;<span class="emphasis"><em>&#27491;&#22312;</em></span>&#26356;&#26032;&#30340;&#25968;&#25454;&#35843;&#29992;lock()&#12290;	</p><p>	    &#36825;&#26159;&#19968;&#20010;&#20363;&#23376;&#65306;	</p><pre class="programlisting">SessionFactory sessions;List fooList;Bar bar;....Session s = sessions.openSession();Transaction tx = null;try {    tx = s.beginTransaction();    fooList = s.find(    	"select foo from eg.Foo foo where foo.Date = current date"        // uses db2 date function    );    bar = (Bar) s.create(Bar.class);    tx.commit();}catch (Exception e) {    if (tx!=null) tx.rollback();    s.close();    throw e;

⌨️ 快捷键说明

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