{"id":1726,"date":"2010-06-08T23:08:10","date_gmt":"2010-06-08T15:08:10","guid":{"rendered":"\/?p=1726"},"modified":"2010-06-08T23:08:10","modified_gmt":"2010-06-08T15:08:10","slug":"1726","status":"publish","type":"post","link":"https:\/\/www.justzz.com\/spec\/1726.html","title":{"rendered":"Hibernate\u4e32\u8bb2\u7b14\u8bb0\u56db"},"content":{"rendered":"<p><strong>\u4e03\u3001Hibernate\u63a7\u5236\u7684\u4e8b\u52a1<\/strong><\/p>\n<p>\u4e8b\u52a1\u4fdd\u8bc1\u539f\u5b50\u64cd\u4f5c\u7684\u4e0d\u53ef\u5206\uff0c\u4e5f\u5c31\u662f\u64cd\u4f5c\u7684\u540c\u65f6\u6210\u529f\u6216\u540c\u65f6\u5931\u8d25\u3002<\/p>\n<p><strong>T<\/strong>ransaction tran=session.beginTranaction();<br \/>\ntran.commit();<br \/>\ntran.rollback();<\/p>\n<p>\u4ee5\u4e0a\u662f\u4e8b\u52a1\u5bf9\u8c61\u7684\u65b9\u6cd5\uff0c\u6765\u5b9e\u73b0\u5bf9\u4e8b\u52a1\u7684\u652f\u6301\u3002<\/p>\n<p>hibernate\u7684\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\uff1a<\/p>\n<p>hibernate\u7684\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\u548cJDBC\u4e2d\u5927\u81f4\u76f8\u540c\u3002<\/p>\n<p>\u8bbe\u7f6e\u65f6\u8981\u5728hibernate.cfg.xml\u914d\u7f6e<\/p>\n<p>&lt;property name=\"hibernate.connection.isolation\"&gt;4&lt;\/property&gt;<\/p>\n<ul>\n<li>1\uff0c\u8bfb\u672a\u63d0\u4ea4\u7684\u6570\u636e\uff08Read uncommitted isolation\uff09<br \/>\n2\uff0c\u8bfb\u5df2\u63d0\u4ea4\u7684\u6570\u636e\uff08Read committed isolation\uff09<br \/>\n4\uff0c\u53ef\u91cd\u590d\u8bfb\u7ea7\u522b\uff08Repeatable read isolation\uff09<br \/>\n8\uff0c\u53ef\u4e32\u884c\u5316\u7ea7\u522b\uff08Serializable isolation\uff09<\/li>\n<\/ul>\n<p><strong>\u516b\u3001Hibernate\u7684\u9501<\/strong>\uff08\u60b2\u89c2\u9501\uff0c\u4e50\u89c2\u9501\uff09<\/p>\n<p>\u60b2\u89c2\u9501\u662f\u7531\u6570\u636e\u5e93\u672c\u8eab\u6240\u5b9e\u73b0\u7684\uff0c\u4f1a\u5bf9\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u8fdb\u884c\u9501\u5b9a\uff0c\u4e5f\u5c31\u662f\u9501\u884c\u3002<\/p>\n<ul>\n<li>LockMode.UPGRADE\u00a0 \u4fee\u6539\u9501\uff0c\u5728get()\u65b9\u6cd5\u4e2d\u52a0\u4e0a\u8fd9\u4e2a\u8bbe\u7f6e\u4f5c\u4e3a\u7b2c\u4e09\u4e2a\u53c2\u6570\u3002<br \/>\nLockMode.NONE\u00a0 \u65e0\u9501\u673a\u5236<br \/>\nLockMode.READ\u00a0 \u8bfb\u53d6\u9501<br \/>\nLockMode.WRITE \u5199\u5165\u9501\uff0c\u4e0d\u80fd\u5728\u7a0b\u5e8f\u4e2d\u76f4\u63a5\u4f7f\u7528<\/li>\n<\/ul>\n<p>\u8fd8\u53ef\u4ee5\u4f7f\u7528Session.lock() Query.setLockMode() Criteria.setLockMode()\u65b9\u6cd5\u6765\u8bbe\u7f6e\u9501<\/p>\n<p>\u4e50\u89c2\u9501\uff0c\u4e5f\u5c31\u662f\u901a\u8fc7\u5bf9\u8bb0\u5f55\u52a0\u4e0a\u67d0\u4e9b\u4fe1\u606f\u6765\u89e3\u51b3\u5e76\u53d1\u8bbf\u95ee\u7684\u95ee\u9898\u3002<\/p>\n<p><strong>\u7248\u672c\u68c0\u67e5<\/strong><\/p>\n<p>\u8981\u5728\u5176\u8868\u4e2d\u591a\u52a0\u4e0a\u4e00\u5217\u8868\u793a\u7248\u672c\u4fe1\u606f\uff0c\u4f1a\u5728\u8bfb\u53d6\u65f6\u8bfb\u5230\u8fd9\u4e2a\u7248\u672c\u53f7\uff0c\u5e76\u5728\u4fee\u6539\u4e4b\u540e\u66f4\u65b0\u8fd9\u4e2a\u7248\u672c\u53f7\uff0c\u5e76\u4e14\u53ea\u6709\u7248\u672c\u53f7\u76f8\u540c\u624d\u4f1a\u4e88\u4ee5\u66f4\u65b0\uff0c\u5982\u679c\u7248\u672c\u53f7\u4f4e\uff0c\u5c31\u4f1a\u629b\u51fa\u4f8b\u5916\u3002<\/p>\n<p>&lt;version name=\"version\" column=\"version\" type=\"integer\" \/&gt;<\/p>\n<p><strong>\u65f6\u95f4\u6233<\/strong><\/p>\n<p>\u4f7f\u7528\u65f6\u95f4\u6233\uff0c\u662f\u901a\u8fc7\u6700\u540e\u4fee\u6539\u65f6\u95f4\u6765\u5224\u65ad\u662f\u5426\u6765\u505a\u66f4\u65b0\u64cd\u4f5c\uff0c\u4e5f\u5c31\u662f\u53ea\u6709\u5728\u6700\u540e\u66f4\u65b0\u65f6\u95f4\u4e4b\u540e\u624d\u4f1a\u505a\u66f4\u65b0\u3002<\/p>\n<p>&lt;timestamp name=\"updateTime\" column=\"updatetime\"\/&gt;<\/p>\n<p><strong>\u4e5d\u3001Hibernate\u7ec4\u4ef6\u6620\u5c04<\/strong><\/p>\n<p>\u7ec4\u4ef6\u4e0d\u4f1a\u751f\u6210\u552f\u4e00\u6807\u8bc6\uff0c\u4f46\u662f\u4e5f\u9700\u8981\u5bf9\u5e94\u5b9e\u4f53\u7c7b\u3002<\/p>\n<p>hibernate\u4e2d\u53ef\u4ee5\u628a\u4e00\u4e2a\u7c7b\u7684\u5bf9\u8c61\u5f53\u4f5c\u4e00\u4e2a\u5c5e\u6027\u7ec4\u4ef6\u6765\u4f7f\u7528\uff0c\u5e76\u4e14\u5728\u4f7f\u7528\u65f6\u4f1a\u81ea\u52a8\u521b\u5efa\uff0c\u6240\u4ee5\u540c\u4e00\u7ec4\u4ef6\u5bf9\u8c61\u662f\u4e0d\u4f1a\u88ab\u4e24\u6b21\u5f15\u7528\u7684\u3002<\/p>\n<p>\u4f8b:<\/p>\n<p><strong>&lt;<\/strong>hibernate-mapping package=\"alan.hbn.rel.inherit\" auto-import=\"false\"&gt;<br \/>\n&lt;class name=\"Guest\" table=\"guest\"&gt;<br \/>\n&lt;id name=\"id\" column=\"id\" type=\"long\" unsaved-value=\"0\"&gt;<br \/>\n&lt;generator class=\"native\"\/&gt;<br \/>\n&lt;\/id&gt;<br \/>\n&lt;property name=\"userName\" column=\"userName\" type=\"string\"\/&gt;<br \/>\n&lt;property name=\"password\" column=\"pwd\"\u00a0\u00a0\u00a0\u00a0 type=\"string\"\/&gt;<br \/>\n&lt;property name=\"birthday\" column=\"birthday\" type=\"date\"\/&gt;<br \/>\n&lt;component name=\"homeAddress\" class=\"Address\"&gt;<br \/>\n&lt;property name=\"street\" column=\"street\" type=\"string\"\/&gt;<br \/>\n&lt;property name=\"zipcode\"\u00a0 column=\"zipcode\"\u00a0 type=\"string\"\/&gt;<br \/>\n&lt;\/component&gt;<br \/>\n&lt;\/class&gt;<br \/>\n&lt;\/hibernate-mapping&gt;<\/p>\n<p>\u56de\u987eJDBC\u90e8\u5206\uff0c\u7ec3\u4e60\u5199\u4e00\u4e2ahibernate\u7684DAO\u5b9e\u73b0\u7c7b\u3002<\/p>\n<p>N\u3001\u8f6f\u4ef6\u7684\u5206\u5c42\u521d\u6b65\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7703\" src=\"https:\/\/www.justzz.com\/spec\/wp-content\/uploads\/sites\/3\/2019\/10\/201068-23727109.jpg\" width=\"573\" height=\"148\" alt=\"201068-23727109\" srcset=\"https:\/\/www.justzz.com\/spec\/files\/2019\/10\/201068-23727109.jpg 573w, https:\/\/www.justzz.com\/spec\/files\/2019\/10\/201068-23727109-300x77.jpg 300w\" sizes=\"auto, (max-width: 573px) 100vw, 573px\" \/><\/p>\n<p>\u8c01\u4f9d\u8d56\u8c01\u5c31\u770b\u8c01\u8c03\u7528\u8c01\u3002<\/p>\n<p>\u8f6f\u4ef6\u7684\u5206\u5c42\u8bbe\u8ba1\uff0c\u4fbf\u4e8e\u4efb\u52a1\u7684\u5212\u5206\u3001\u964d\u4f4e\u5c42\u95f4\u7684\u8026\u5408\u3002<\/p>\n<p>\u7ed3\u5408PMS\u7684\u8bbe\u8ba1\u65b9\u6cd5\uff0c\u601d\u8003\u8fd9\u6837\u5206\u5c42\u7684\u597d\u5904\u3002<\/p>\n<p>\u5e76\u4e14\uff0c\u4f7f\u4ee3\u7801\u5c3d\u91cf\u51cf\u5c11\u91cd\u590d\uff0c\u53ef\u590d\u7528\u6027\u597d\uff0c\u6269\u5c55\u4f59\u5730\u52a0\u5927\uff0c\u800c\u4e14\u5c3d\u91cf\u51cf\u5c11\u786c\u7f16\u7801\u3002<\/p>\n<p>\u9700\u6c42\uff1a\u5b9e\u73b0\u5bf9Person\u7c7b\u7684\u6570\u636e\u5e93\u6301\u4e45\u5316\u57fa\u672c\u64cd\u4f5c\uff08CRUD\uff09\u3002<\/p>\n<p>\u5305\u7ed3\u6784\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7704\" src=\"https:\/\/www.justzz.com\/spec\/wp-content\/uploads\/sites\/3\/2019\/10\/201068-23746750.jpg\" width=\"554\" height=\"341\" alt=\"201068-23746750\" srcset=\"https:\/\/www.justzz.com\/spec\/files\/2019\/10\/201068-23746750.jpg 554w, https:\/\/www.justzz.com\/spec\/files\/2019\/10\/201068-23746750-300x185.jpg 300w\" sizes=\"auto, (max-width: 554px) 100vw, 554px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e03\u3001Hibernate\u63a7\u5236\u7684\u4e8b\u52a1 \u4e8b\u52a1\u4fdd\u8bc1\u539f\u5b50\u64cd\u4f5c\u7684\u4e0d\u53ef\u5206\uff0c\u4e5f\u5c31\u662f\u64cd\u4f5c\u7684\u540c\u65f6\u6210\u529f\u6216\u540c\u65f6\u5931\u8d25\u3002 Transaction tran=session.beginTranaction(); tran.commit(); tran.rollback(); \u4ee5\u4e0a&hellip;<\/p>\n","protected":false},"author":13,"featured_media":7704,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1726","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-t"],"_links":{"self":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/posts\/1726","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/comments?post=1726"}],"version-history":[{"count":0,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/posts\/1726\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/media\/7704"}],"wp:attachment":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/media?parent=1726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/categories?post=1726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/tags?post=1726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}