{"id":1887,"date":"2017-01-07T09:08:43","date_gmt":"2017-01-07T01:08:43","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=1887"},"modified":"2026-08-18T11:20:30","modified_gmt":"2026-08-18T03:20:30","slug":"hibernate%e5%bf%ab%e9%80%9f%e5%ad%a6%e4%b9%a0","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=1887","title":{"rendered":"Hibernate\u5feb\u901f\u5b66\u4e60"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">Hibernate<\/strong> \u662f\u6570\u636e\u6301\u4e45\u5c42\u91cc\u5e38\u7528\u7684\u8f7b\u91cf\u7ea7\u6846\u67b6\u3002\u540c\u7c7b\u8fd8\u6709 iBATIS\u3001MyBatis\u3001NHibernate\u3001Siena \u7b49\u3002\u5b83\u662f\u4e00\u5957\u5f00\u6e90\u7684 <strong style=\"color: #4870ac;\">ORM\uff08Object-Relational Mapping\uff09<\/strong>\uff0c\u7528\u9762\u5411\u5bf9\u8c61\u7684\u65b9\u5f0f\u67e5\u8be2\u548c\u64cd\u4f5c\u6570\u636e\u5e93\uff0c\u628a\u5927\u91cf JDBC \u6837\u677f\u4ee3\u7801\u4ece\u4e1a\u52a1\u91cc\u62ff\u6389\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u4e0a\u624b\u65f6\u5148\u6293\u4f4f\u4e24\u4ef6\u4e8b\uff1a\u4e94\u4e2a\u6838\u5fc3\u63a5\u53e3\u5404\u81ea\u5e72\u4ec0\u4e48\uff0c\u4ee5\u53ca\u4ece JDBC \u5c01\u88c5\u3001\u5206\u5c42\u3001ORM \u4e09\u4e2a\u89d2\u5ea6\u770b\u5b83\u5230\u5e95\u7ad9\u5728\u54ea\u4e00\u5c42\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e00\u3001Hibernate \u4ecb\u7ecd<\/h2>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">1. \u4ec0\u4e48\u662f Hibernate<\/h3>\n<p style=\"margin: 1em 0px;\">Hibernate \u628a\u5bf9\u8c61\u548c\u5173\u7cfb\u8868\u5bf9\u4e0a\uff0c\u63d0\u4f9b\u67e5\u8be2\u4e0e\u83b7\u53d6\u6570\u636e\u7684\u65b9\u6cd5\u3002\u5f00\u53d1\u65f6\u6309\u5bf9\u8c61\u601d\u8003\uff0c\u800c\u4e0d\u662f\u624b\u5199\u4e00\u6574\u6bb5 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">insert \/ update<\/code>\u3002<\/p>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">2. Hibernate \u7684\u4f18\u70b9<\/h3>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>\u4f7f\u7528\u7b80\u6d01\u7684 <strong style=\"color: #4870ac;\">HQL<\/strong>\uff08Hibernate Query Language\uff09\uff0c\u53ef\u4ee5\u4e0d\u518d\u624b\u5199\u4f20\u7edf\u7684 insert\u3001update\u3002\u4f8b\u5982\u63d2\u5165\u4e00\u6761\u8bb0\u5f55\uff0c\u539f\u6765\u662f <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">insert into \u8868\u540d values(\u503c1, \u503c2, \u2026)<\/code>\uff0c\u73b0\u5728\u662f <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">save(\u5bf9\u8c61)<\/code>\u3002<\/section>\n<\/li>\n<li>\n<section>\u4f7f\u7528 ORM \u6620\u5c04\uff1a\u4ece\u5bf9\u8c61\u7684\u89d2\u5ea6\u64cd\u4f5c\u6570\u636e\u5e93\u3002\u4ee5\u524d\u5e38\u89c1\u6d41\u7a0b\u662f\u5148\u6709\u8868\u518d\u62bd\u5b9e\u4f53\uff1bHibernate \u8fd9\u8fb9\u662f\u5bf9\u8c61\u6620\u5c04\u5230\u8868\u3002<\/section>\n<\/li>\n<li>\n<section>\u6ca1\u6709\u4fb5\u5165\u6027\uff0c\u79fb\u690d\u6027\u8f83\u597d\u3002\u5b83\u4f7f\u7528 <strong style=\"color: #4870ac;\">POJO<\/strong>\uff1a\u4e0d\u7ee7\u627f Hibernate \u7c7b\u3001\u4e5f\u4e0d\u5b9e\u73b0 Hibernate \u63a5\u53e3\uff0c\u5c31\u662f\u666e\u901a Java \u7c7b\uff0c\u6362\u6301\u4e45\u5c42\u65f6\u66f4\u5bb9\u6613\u5e26\u8d70\u3002<\/section>\n<\/li>\n<li>\n<section>\u652f\u6301\u900f\u660e\u6301\u4e45\u5316\u3002\u4e09\u5c42\u67b6\u6784\u91cc\u4e0a\u5c42\u53ea\u4f9d\u8d56\u63a5\u53e3\uff1bHibernate \u5bf9\u4e1a\u52a1\u5c42\u63d0\u4f9b <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">Session<\/code>\uff0c\u5176\u4f59\u5c01\u88c5\u8d77\u6765\u3002\u6301\u4e45\u5316\u672c\u8eab\u662f\u6307\u628a\u5185\u5b58\u4e2d\u7684\u6570\u636e\u843d\u5230\u78c1\u76d8\u3002<\/section>\n<\/li>\n<\/ul>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">3. Hibernate \u4e2d 5 \u4e2a\u6838\u5fc3\u63a5\u53e3<\/h3>\n<table style=\"display: table; text-align: left; overflow: auto; border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; overflow-wrap: break-word; word-break: break-all;\" width=\"800\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u63a5\u53e3<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u804c\u8d23<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u6ce8\u610f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">Configuration<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u914d\u7f6e\u5e76\u542f\u52a8 Hibernate\uff0c\u7528\u6765\u521b\u5efa SessionFactory<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u8bfb\u914d\u7f6e\u3001\u5efa\u5de5\u5382<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">SessionFactory<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5bf9\u5e94\u4e00\u4e2a\u6570\u636e\u6e90\uff1b\u4e00\u4e2a\u6570\u636e\u5e93\u5bf9\u5e94\u4e00\u4e2a SessionFactory\uff0c\u7528\u6765\u521b\u5efa Session<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><strong style=\"color: #4870ac;\">\u7ebf\u7a0b\u5b89\u5168<\/strong>\uff0c\u53ef\u591a\u7ebf\u7a0b\u5171\u4eab<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">Session<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6700\u5e38\u7528\uff0c\u8d1f\u8d23\u589e\u5220\u6539\u67e5<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><strong style=\"color: #4870ac;\">\u975e\u7ebf\u7a0b\u5b89\u5168<\/strong>\uff0c\u4e0d\u80fd\u5171\u4eab<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">Query<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6570\u636e\u5e93\u67e5\u8be2\u5bf9\u8c61<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">HQL \/ Criteria \u90fd\u4ece\u8fd9\u91cc\u8d70<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">Transaction<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5c01\u88c5\u5e95\u5c42\u4e8b\u52a1\uff0c\u4f8b\u5982 JTA\uff08Java Transaction Architecture\uff09<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u589e\u5220\u6539\u67e5\u90fd\u5e94\u5305\u5728\u4e8b\u52a1\u91cc<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e8c\u3001\u4ece\u4e09\u4e2a\u89d2\u5ea6\u7406\u89e3 Hibernate<\/h2>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">1. \u5bf9 JDBC \u7684\u8fdb\u4e00\u6b65\u5c01\u88c5<\/h3>\n<p style=\"margin: 1em 0px;\">\u6ca1\u7528 Hibernate \u505a\u6301\u4e45\u5c42\u65f6\uff0cJDBC \u8bed\u53e5\u3001Connection \u7ba1\u7406\u5230\u5904\u91cd\u590d\u3002Hibernate \u628a JDBC \u5c01\u4e86\u4e00\u5c42\uff0c\u4e1a\u52a1\u4e0d\u518d\u76f4\u63a5\u62fc SQL\u3001\u7ba1\u8fde\u63a5\uff0c\u800c\u662f\u64cd\u4f5c Session \/ \u5bf9\u8c61\u3002<\/p>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">2. \u4ece\u5206\u5c42\u89d2\u5ea6\u770b<\/h3>\n<p style=\"margin: 1em 0px;\">\u5178\u578b\u4e09\u5c42\u662f\u8868\u793a\u5c42\u3001\u4e1a\u52a1\u5c42\u3001\u6301\u4e45\u5c42\u3002Hibernate \u5c5e\u4e8e<strong style=\"color: #4870ac;\">\u6301\u4e45\u5c42<\/strong>\u3002\u8fd9\u4e00\u5c42\u8fd8\u6709 iBATIS\u3001NHibernate\u3001JDO\u3001OJB\u3001EJB \u7b49\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2017\/01\/h1.jpeg\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1889\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2017\/01\/h1.jpeg\" alt=\"h1\" width=\"888\" height=\"431\" \/><\/a><\/p>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">3. \u5f00\u6e90 ORM \u6846\u67b6<\/h3>\n<p style=\"margin: 1em 0px;\">ORM \u5373 Object-Relational Mapping\uff1a\u5728\u5173\u7cfb\u5e93\u548c\u5bf9\u8c61\u4e4b\u95f4\u505a\u6620\u5c04\uff0c\u4ece\u5bf9\u8c61\u5230\u5173\u7cfb\uff0c\u518d\u4ece\u5173\u7cfb\u56de\u5230\u5bf9\u8c61\u3002\u64cd\u4f5c\u6570\u636e\u5e93\u65f6\u4e0d\u5fc5\u53cd\u590d\u548c\u590d\u6742 SQL \u7ea0\u7f20\uff0c\u50cf\u64cd\u4f5c\u5bf9\u8c61\u4e00\u6837\u5373\u53ef\u2014\u2014\u628a\u8868\u5b57\u6bb5\u5728\u5185\u5b58\u91cc\u6620\u5c04\u6210\u5bf9\u8c61\u5c5e\u6027\u3002<\/p>\n<p style=\"margin: 1em 0px;\">Hibernate \u7684\u6838\u5fc3\u5173\u7cfb\u5982\u4e0b\u56fe\uff1a\u516d\u5927\u6838\u5fc3\u63a5\u53e3\u3001\u4e24\u4efd\u4e3b\u8981\u914d\u7f6e\u6587\u4ef6\uff0c\u4ee5\u53ca\u5b83\u4eec\u4e4b\u95f4\u600e\u4e48\u4e32\u8d77\u6765\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2017\/01\/h4.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1892\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2017\/01\/h4.png\" alt=\"h4\" width=\"666\" height=\"524\" \/><\/a><\/p>\n<blockquote style=\"display: block; font-size: 0.9em; border-left: 3px solid #4870ac; padding: 0.5em 1em; margin: 0px; background: #f6f8fa; color: #40464f;\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1aHibernate \u662f\u6301\u4e45\u5c42\u7684 ORM\uff0c\u7528 Session \u5c01\u88c5 JDBC\uff1bSessionFactory \u7ebf\u7a0b\u5b89\u5168\u3001Session \u4e0d\u5171\u4eab\uff0c\u589e\u5220\u6539\u67e5\u90fd\u653e\u8fdb\u4e8b\u52a1\u91cc\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>Hibernate \u662f\u6570\u636e\u6301\u4e45\u5c42\u91cc\u5e38\u7528\u7684\u8f7b\u91cf\u7ea7\u6846\u67b6\u3002\u540c\u7c7b\u8fd8\u6709 iBATIS\u3001MyBatis\u3001NHibernat [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[89],"tags":[189],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1887"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1887"}],"version-history":[{"count":3,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1887\/revisions"}],"predecessor-version":[{"id":1893,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1887\/revisions\/1893"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1887"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1887"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}