{"id":50730,"date":"2023-12-23T10:31:39","date_gmt":"2023-12-23T02:31:39","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%b3%a8%e8%a7%a3%e7%9a%84%e7%a4%ba%e4%be%8b%ef%bc%9ahibernate%e4%b8%80%e5%af%b9%e4%b8%80%e6%98%a0%e5%b0%84\/"},"modified":"2023-12-23T15:32:43","modified_gmt":"2023-12-23T07:32:43","slug":"%e6%b3%a8%e8%a7%a3%e7%9a%84%e7%a4%ba%e4%be%8b%ef%bc%9ahibernate%e4%b8%80%e5%af%b9%e4%b8%80%e6%98%a0%e5%b0%84","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%b3%a8%e8%a7%a3%e7%9a%84%e7%a4%ba%e4%be%8b%ef%bc%9ahibernate%e4%b8%80%e5%af%b9%e4%b8%80%e6%98%a0%e5%b0%84\/","title":{"rendered":"\u6ce8\u89e3\u7684\u793a\u4f8b\uff1aHibernate\u4e00\u5bf9\u4e00\u6620\u5c04"},"content":{"rendered":"<p>\u4eca\u5929\u6211\u4eec\u5c06\u5b66\u4e60Hibernate\u4e2d\u7684\u4e00\u5bf9\u4e00\u6620\u5c04\u3002\u6211\u4eec\u5c06\u4ecb\u7ecd\u4f7f\u7528\u6ce8\u89e3\u548cXML\u914d\u7f6e\u7684Hibernate\u4e00\u5bf9\u4e00\u6620\u5c04\u793a\u4f8b\u3002<\/p>\n<h2>Hibernate\u4e2d\u7684\u4e00\u5bf9\u4e00\u6620\u5c04\u3002<\/h2>\n<p>\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u6570\u636e\u5e93\u8868\u4e4b\u95f4\u662f\u76f8\u4e92\u5173\u8054\u7684\u3002\u5173\u8054\u53ef\u4ee5\u6709\u591a\u79cd\u5f62\u5f0f &#8211; \u4e00\u5bf9\u4e00\u3001\u4e00\u5bf9\u591a\u548c\u591a\u5bf9\u591a\u662f\u5728\u66f4\u5e7f\u6cdb\u7684\u5c42\u9762\u4e0a\u3002\u8fd9\u4e9b\u53ef\u4ee5\u8fdb\u4e00\u6b65\u5206\u4e3a\u5355\u5411\u548c\u53cc\u5411\u6620\u5c04\u3002\u4eca\u5929\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528XML\u914d\u7f6e\u548c\u6ce8\u91ca\u914d\u7f6e\u6765\u5b9e\u73b0Hibernate\u7684\u4e00\u5bf9\u4e00\u6620\u5c04\u3002<\/p>\n<h3>Hibernate\u4e00\u5bf9\u4e00\u6620\u5c04\u793a\u4f8b\u6570\u636e\u5e93\u8bbe\u7f6e<\/h3>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728\u6570\u636e\u5e93\u8868\u4e2d\u8bbe\u7f6e\u4e00\u5bf9\u4e00\u6620\u5c04\u3002\u6211\u4eec\u5c06\u4e3a\u6211\u4eec\u7684\u793a\u4f8b\u521b\u5efa\u4e24\u4e2a\u8868 &#8211; Transaction\uff08\u4ea4\u6613\uff09\u548cCustomer\uff08\u987e\u5ba2\uff09\u3002\u8fd9\u4e24\u4e2a\u8868\u5c06\u5177\u6709\u4e00\u5bf9\u4e00\u7684\u6620\u5c04\u5173\u7cfb\u3002Transaction\u5c06\u662f\u4e3b\u8868\uff0c\u6211\u4eec\u5c06\u5728Customer\u8868\u4e2d\u4f7f\u7528\u5916\u952e\u8fdb\u884c\u4e00\u5bf9\u4e00\u6620\u5c04\u3002\u6211\u5c06\u63d0\u4f9bMySQL\u811a\u672c\uff0c\u8fd9\u662f\u6211\u7528\u4e8e\u672c\u6559\u7a0b\u7684\u6570\u636e\u5e93\u3002\u5982\u679c\u60a8\u4f7f\u7528\u5176\u4ed6\u6570\u636e\u5e93\uff0c\u8bf7\u786e\u4fdd\u76f8\u5e94\u5730\u66f4\u6539\u811a\u672c\u3002<\/p>\n<pre class=\"post-pre\"><code>-- Create Transaction Table\r\nCREATE TABLE `Transaction` (\r\n  `txn_id` int(11) unsigned NOT NULL AUTO_INCREMENT,\r\n  `txn_date` date NOT NULL,\r\n  `txn_total` decimal(10,0) NOT NULL,\r\n  PRIMARY KEY (`txn_id`)\r\n) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8;\r\n\r\n-- Create Customer table\r\nCREATE TABLE `Customer` (\r\n  `txn_id` int(11) unsigned NOT NULL,\r\n  `cust_name` varchar(20) NOT NULL DEFAULT '',\r\n  `cust_email` varchar(20) DEFAULT NULL,\r\n  `cust_address` varchar(50) NOT NULL DEFAULT '',\r\n  PRIMARY KEY (`txn_id`),\r\n  CONSTRAINT `customer_ibfk_1` FOREIGN KEY (`txn_id`) REFERENCES `Transaction` (`txn_id`)\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\r\n<\/code><\/pre>\n<p>\u4e0a\u8ff0\u8868\u683c\u4e4b\u95f4\u7684\u4e00\u5bf9\u4e00\u6620\u5c04\u7684\u5b9e\u4f53\u5173\u7cfb\u56fe\uff08ERD\uff09\u5982\u4e0b\u56fe\u6240\u793a\u3002\u6211\u4eec\u7684\u6570\u636e\u5e93\u8bbe\u7f6e\u5df2\u7ecf\u51c6\u5907\u597d\u4e86\uff0c\u73b0\u5728\u8ba9\u6211\u4eec\u7ee7\u7eed\u8fdb\u884cHibernate\u4e00\u5bf9\u4e00\u793a\u4f8b\u9879\u76ee\u3002<\/p>\n<h3>\u5728\u6b64\u9879\u76ee\u4e2d\uff0c\u63d0\u4f9b\u4e86\u4e00\u4e2aHibernate\u7684\u4e00\u5bf9\u4e00\u6620\u5c04\u793a\u4f8b\u9879\u76ee\u7ed3\u6784\u3002<\/h3>\n<p>\u5728\u4f60\u7684Java IDE\u4e2d\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Maven\u9879\u76ee\uff0c\u6211\u4f7f\u7528\u7684\u662fEclipse\u3002\u6211\u4eec\u6700\u540e\u7684\u9879\u76ee\u7ed3\u6784\u5c06\u5982\u4e0b\u56fe\u6240\u793a\u3002\u9996\u5148\uff0c\u6211\u4eec\u5c06\u7814\u7a76\u57fa\u4e8eXML\u7684Hibernate\u4e00\u5bf9\u4e00\u6620\u5c04\u793a\u4f8b\uff0c\u7136\u540e\u6211\u4eec\u5c06\u4f7f\u7528\u6ce8\u91ca\u5b9e\u73b0\u76f8\u540c\u7684\u5185\u5bb9\u3002<\/p>\n<h3>Maven\u4f9d\u8d56\u7684Hibernate<\/h3>\n<p>\u6211\u4eec\u6700\u7ec8\u7684pom.xml\u6587\u4ef6\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre class=\"post-pre\"><code>&lt;project xmlns=\"https:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"https:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:schemaLocation=\"https:\/\/maven.apache.org\/POM\/4.0.0 https:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"&gt;\r\n  &lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\r\n  &lt;groupId&gt;com.Olivia.hibernate&lt;\/groupId&gt;\r\n  &lt;artifactId&gt;HibernateOneToOneMapping&lt;\/artifactId&gt;\r\n  &lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\r\n  &lt;dependencies&gt;\r\n  \t&lt;dependency&gt;\r\n  \t\t&lt;groupId&gt;org.hibernate&lt;\/groupId&gt;\r\n  \t\t&lt;artifactId&gt;hibernate-core&lt;\/artifactId&gt;\r\n  \t\t&lt;version&gt;4.3.5.Final&lt;\/version&gt;\r\n  \t&lt;\/dependency&gt;\r\n  \t&lt;dependency&gt;\r\n  \t\t&lt;groupId&gt;mysql&lt;\/groupId&gt;\r\n  \t\t&lt;artifactId&gt;mysql-connector-java&lt;\/artifactId&gt;\r\n  \t\t&lt;version&gt;5.0.5&lt;\/version&gt;\r\n  \t&lt;\/dependency&gt;\r\n  &lt;\/dependencies&gt;\r\n&lt;\/project&gt;\r\n<\/code><\/pre>\n<p>\u4f9d\u8d56\u9879\u4ec5\u9002\u7528\u4e8eHibernate\u548cMySQL\u7684Java\u9a71\u52a8\u7a0b\u5e8f\u3002\u8bf7\u6ce8\u610f\uff0c\u6211\u6b63\u5728\u4f7f\u7528\u6700\u65b0\u7248\u672c\u7684Hibernate\uff084.3.5.Final\uff09\u548c\u6839\u636e\u6211\u7684MySQL\u6570\u636e\u5e93\u670d\u52a1\u5668\u7248\u672c\uff085.0.5\uff09\u9009\u62e9\u7684MySQL Java\u9a71\u52a8\u7a0b\u5e8f\u3002Hibernate 4\u4f7f\u7528JBoss\u65e5\u5fd7\u8bb0\u5f55\uff0c\u5e76\u4f5c\u4e3a\u4f20\u9012\u4f9d\u8d56\u9879\u81ea\u52a8\u5bfc\u5165\u3002\u60a8\u53ef\u4ee5\u5728\u9879\u76ee\u7684Maven\u4f9d\u8d56\u9879\u4e2d\u786e\u8ba4\u3002\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f\u8f83\u65e7\u7248\u672c\u7684Hibernate\uff0c\u5219\u53ef\u80fd\u9700\u8981\u6dfb\u52a0slf4j\u4f9d\u8d56\u9879\u3002<\/p>\n<h3>\u4f7f\u7528Hibernate\u5b9e\u73b0\u4e00\u5bf9\u4e00\u6620\u5c04\u6a21\u578b\u7c7b<\/h3>\n<p>\u53cd\u6620\u6570\u636e\u5e93\u8868\u7684Hibernate\u4e00\u5bf9\u4e00\u6620\u5c04\u7684\u6a21\u578b\u7c7b\u5c06\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.Olivia.hibernate.model;\r\n\r\nimport java.util.Date;\r\n\r\npublic class Txn {\r\n\r\n\tprivate long id;\r\n\tprivate Date date;\r\n\tprivate double total;\r\n\tprivate Customer customer;\r\n\t\r\n\t@Override\r\n\tpublic String toString(){\r\n\t\treturn id+\", \"+total+\", \"+customer.getName()+\", \"+customer.getEmail()+\", \"+customer.getAddress();\r\n\t}\r\n\tpublic long getId() {\r\n\t\treturn id;\r\n\t}\r\n\tpublic void setId(long id) {\r\n\t\tthis.id = id;\r\n\t}\r\n\tpublic Date getDate() {\r\n\t\treturn date;\r\n\t}\r\n\tpublic void setDate(Date date) {\r\n\t\tthis.date = date;\r\n\t}\r\n\tpublic double getTotal() {\r\n\t\treturn total;\r\n\t}\r\n\tpublic void setTotal(double total) {\r\n\t\tthis.total = total;\r\n\t}\r\n\tpublic Customer getCustomer() {\r\n\t\treturn customer;\r\n\t}\r\n\tpublic void setCustomer(Customer customer) {\r\n\t\tthis.customer = customer;\r\n\t}\r\n\t\r\n}\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code>package com.Olivia.hibernate.model;\r\n\r\npublic class Customer {\r\n\r\n\tprivate long id;\r\n\tprivate String name;\r\n\tprivate String email;\r\n\tprivate String address;\r\n\t\r\n\tprivate Txn txn;\r\n\t\r\n\tpublic long getId() {\r\n\t\treturn id;\r\n\t}\r\n\tpublic void setId(long id) {\r\n\t\tthis.id = id;\r\n\t}\r\n\tpublic String getName() {\r\n\t\treturn name;\r\n\t}\r\n\tpublic void setName(String name) {\r\n\t\tthis.name = name;\r\n\t}\r\n\tpublic String getEmail() {\r\n\t\treturn email;\r\n\t}\r\n\tpublic void setEmail(String email) {\r\n\t\tthis.email = email;\r\n\t}\r\n\tpublic String getAddress() {\r\n\t\treturn address;\r\n\t}\r\n\tpublic void setAddress(String address) {\r\n\t\tthis.address = address;\r\n\t}\r\n\tpublic Txn getTxn() {\r\n\t\treturn txn;\r\n\t}\r\n\tpublic void setTxn(Txn txn) {\r\n\t\tthis.txn = txn;\r\n\t}\r\n\t\r\n}\r\n<\/code><\/pre>\n<p>\u7531\u4e8e\u6211\u4eec\u4f7f\u7528\u57fa\u4e8eXML\u7684\u914d\u7f6e\u8fdb\u884c\u6620\u5c04\uff0c\u4ee5\u4e0a\u7684\u6a21\u578b\u7c7b\u662f\u7b80\u5355\u7684POJO\u7c7b\u6216\u8005Java Beans\uff0c\u5177\u6709getter-setter\u65b9\u6cd5\u3002\u6211\u5c06\u4f7f\u7528Txn\u4f5c\u4e3a\u7c7b\u540d\uff0c\u4ee5\u514d\u4e0eHibernate\u7684API\u4e2d\u7684Transaction\u7c7b\u6df7\u6dc6\u3002<\/p>\n<h3>\u4e00\u5bf9\u4e00\u6620\u5c04\u914d\u7f6e\u7684 Hibernate \u914d\u7f6e<\/h3>\n<p>\u8ba9\u6211\u4eec\u4e3aTxn\u548cCustomer\u8868\u521b\u5efa\u4e00\u5bf9\u4e00\u6620\u5c04\u7684Hibernate\u914d\u7f6e\u6587\u4ef6\u3002txn.hbm.xml<\/p>\n<pre class=\"post-pre\"><code>&lt;?xml version=\"1.0\"?&gt;\r\n&lt;!DOCTYPE hibernate-mapping PUBLIC \"-\/\/Hibernate\/Hibernate Mapping DTD 3.0\/\/EN\"\r\n\t\"https:\/\/hibernate.org\/dtd\/hibernate-mapping-3.0.dtd\"&gt;\r\n&lt;hibernate-mapping&gt;\r\n\t&lt;class name=\"com.Olivia.hibernate.model.Txn\" table=\"TRANSACTION\" &gt;\r\n\t\t&lt;id name=\"id\" type=\"long\"&gt;\r\n\t\t\t&lt;column name=\"txn_id\" \/&gt;\r\n\t\t\t&lt;generator class=\"identity\" \/&gt;\r\n\t\t&lt;\/id&gt;\r\n\t\t&lt;property name=\"date\" type=\"date\"&gt;\r\n\t\t\t&lt;column name=\"txn_date\" \/&gt;\r\n\t\t&lt;\/property&gt;\r\n\t\t&lt;property name=\"total\" type=\"double\"&gt;\r\n\t\t\t&lt;column name=\"txn_total\" \/&gt;\r\n\t\t&lt;\/property&gt;\r\n\t\t&lt;one-to-one name=\"customer\" class=\"com.Olivia.hibernate.model.Customer\"\r\n\t\t\tcascade=\"save-update\" \/&gt;\r\n\t&lt;\/class&gt;\r\n\t\r\n&lt;\/hibernate-mapping&gt;\r\n<\/code><\/pre>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u91cd\u8981\u4e00\u70b9\u662f\u5ba2\u6237\u5c5e\u6027\u4e2d\u5173\u4e8e hibernate \u4e00\u5bf9\u4e00\u5143\u7d20\u7684\u90e8\u5206\u3002customer.hbm.xml<\/p>\n<pre class=\"post-pre\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;!DOCTYPE hibernate-mapping PUBLIC \"-\/\/Hibernate\/Hibernate Mapping DTD 3.0\/\/EN\" \r\n\"https:\/\/hibernate.org\/dtd\/hibernate-mapping-3.0.dtd\" &gt;\r\n&lt;hibernate-mapping&gt;\r\n\r\n\t&lt;class name=\"com.Olivia.hibernate.model.Customer\" table=\"CUSTOMER\"&gt;\r\n\t\t&lt;id name=\"id\" type=\"long\"&gt;\r\n\t\t\t&lt;column name=\"txn_id\" \/&gt;\r\n\t\t\t&lt;generator class=\"foreign\"&gt;\r\n\t\t\t\t&lt;param name=\"property\"&gt;txn&lt;\/param&gt;\r\n\t\t\t&lt;\/generator&gt;\r\n\t\t&lt;\/id&gt;\r\n\t\t&lt;one-to-one name=\"txn\" class=\"com.Olivia.hibernate.model.Txn\"\r\n\t\t\tconstrained=\"true\"&gt;&lt;\/one-to-one&gt;\r\n\r\n\t\t&lt;property name=\"name\" type=\"string\"&gt;\r\n\t\t\t&lt;column name=\"cust_name\"&gt;&lt;\/column&gt;\r\n\t\t&lt;\/property&gt;\r\n\t\t&lt;property name=\"email\" type=\"string\"&gt;\r\n\t\t\t&lt;column name=\"cust_email\"&gt;&lt;\/column&gt;\r\n\t\t&lt;\/property&gt;\r\n\t\t&lt;property name=\"address\" type=\"string\"&gt;\r\n\t\t\t&lt;column name=\"cust_address\"&gt;&lt;\/column&gt;\r\n\t\t&lt;\/property&gt;\r\n\t&lt;\/class&gt;\r\n\r\n&lt;\/hibernate-mapping&gt;\r\n<\/code><\/pre>\n<p>\u751f\u6210\u5668\u7c7b\u201cforeign\u201d\u662f\u7528\u4e8e\u5b9e\u73b0Hibernate\u5916\u952e\u7684\u91cd\u8981\u90e8\u5206\u3002<\/p>\n<h3>Hibernate\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u8fd9\u662f\u4e00\u4e2a\u7528\u4e8e\u57fa\u4e8eXML\u7684Hibernate\u6620\u5c04\u914d\u7f6e\u7684Hibernate\u914d\u7f6e\u6587\u4ef6\u3002hibernate.cfg.xml<\/p>\n<pre class=\"post-pre\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;!DOCTYPE hibernate-configuration PUBLIC\r\n\t\t\"-\/\/Hibernate\/Hibernate Configuration DTD 3.0\/\/EN\"\r\n\t\t\"https:\/\/hibernate.org\/dtd\/hibernate-configuration-3.0.dtd\"&gt;\r\n&lt;hibernate-configuration&gt;\r\n    &lt;session-factory&gt;\r\n        &lt;property name=\"hibernate.connection.driver_class\"&gt;com.mysql.jdbc.Driver&lt;\/property&gt;\r\n        &lt;property name=\"hibernate.connection.password\"&gt;pankaj123&lt;\/property&gt;\r\n        &lt;property name=\"hibernate.connection.url\"&gt;jdbc:mysql:\/\/localhost\/TestDB&lt;\/property&gt;\r\n        &lt;property name=\"hibernate.connection.username\"&gt;pankaj&lt;\/property&gt;\r\n        &lt;property name=\"hibernate.dialect\"&gt;org.hibernate.dialect.MySQLDialect&lt;\/property&gt;\r\n        \r\n        &lt;property name=\"hibernate.current_session_context_class\"&gt;thread&lt;\/property&gt;\r\n        &lt;property name=\"hibernate.show_sql\"&gt;true&lt;\/property&gt;\r\n        \r\n        &lt;mapping resource=\"txn.hbm.xml\"\/&gt;\r\n        &lt;mapping resource=\"customer.hbm.xml\"\/&gt;\r\n    &lt;\/session-factory&gt;\r\n&lt;\/hibernate-configuration&gt;\r\n<\/code><\/pre>\n<p>Hibernate\u914d\u7f6e\u6587\u4ef6\u5f88\u7b80\u5355\uff0c\u5b83\u5305\u542b\u4e86\u6570\u636e\u5e93\u8fde\u63a5\u5c5e\u6027\u548cHibernate\u6620\u5c04\u8d44\u6e90\u3002<\/p>\n<h3>Hibernate\u4f1a\u8bdd\u5de5\u5382\u5de5\u5177 <\/h3>\n<p>\u8fd9\u662f\u521b\u5efaHibernate SessionFactory\u5b9e\u4f8b\u7684\u5b9e\u7528\u7c7b\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.Olivia.hibernate.util;\r\n\r\nimport org.hibernate.SessionFactory;\r\nimport org.hibernate.boot.registry.StandardServiceRegistryBuilder;\r\nimport org.hibernate.cfg.Configuration;\r\nimport org.hibernate.service.ServiceRegistry;\r\n\r\npublic class HibernateUtil {\r\n\r\n\tprivate static SessionFactory sessionFactory;\r\n\t\r\n\tprivate static SessionFactory buildSessionFactory() {\r\n        try {\r\n            \/\/ Create the SessionFactory from hibernate.cfg.xml\r\n        \tConfiguration configuration = new Configuration();\r\n        \tconfiguration.configure(\"hibernate.cfg.xml\");\r\n        \tSystem.out.println(\"Hibernate Configuration loaded\");\r\n        \t\r\n        \tServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();\r\n        \tSystem.out.println(\"Hibernate serviceRegistry created\");\r\n        \t\r\n        \tSessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);\r\n        \t\r\n            return sessionFactory;\r\n        }\r\n        catch (Throwable ex) {\r\n            System.err.println(\"Initial SessionFactory creation failed.\" + ex);\r\n            ex.printStackTrace();\r\n            throw new ExceptionInInitializerError(ex);\r\n        }\r\n    }\r\n\t\r\n\tpublic static SessionFactory getSessionFactory() {\r\n\t\tif(sessionFactory == null) sessionFactory = buildSessionFactory();\r\n        return sessionFactory;\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>\u5c31\u8fd9\u6837\u5427\uff0c\u6211\u4eec\u6765\u7f16\u5199\u4e00\u4e2a\u6d4b\u8bd5\u7a0b\u5e8f\uff0c\u6d4b\u8bd5\u57fa\u4e8eHibernate\u4e00\u5bf9\u4e00\u6620\u5c04\u7684XML\u914d\u7f6e\u3002<\/p>\n<h3>XML Configuration\u7a0b\u5e8f\u8fdb\u884cHibernate\u4e00\u5bf9\u4e00\u6620\u5c04\u6d4b\u8bd5\u3002<\/h3>\n<p>\u5728\u4e00\u5bf9\u4e00\u6620\u5c04\u793a\u4f8b\u6d4b\u8bd5\u7a0b\u5e8f\u4e2d\uff0c\u9996\u5148\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2a Txn \u5bf9\u8c61\u5e76\u4fdd\u5b58\u5b83\u3002\u4e00\u65e6\u5b83\u4fdd\u5b58\u5230\u6570\u636e\u5e93\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u751f\u6210\u7684\u6807\u8bc6\u7b26\u6765\u68c0\u7d22 Txn \u5bf9\u8c61\u5e76\u6253\u5370\u51fa\u6765\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.Olivia.hibernate.main;\r\n\r\nimport java.util.Date;\r\n\r\nimport org.hibernate.Session;\r\nimport org.hibernate.SessionFactory;\r\nimport org.hibernate.Transaction;\r\n\r\nimport com.Olivia.hibernate.model.Customer;\r\nimport com.Olivia.hibernate.model.Txn;\r\nimport com.Olivia.hibernate.util.HibernateUtil;\r\n\r\npublic class HibernateOneToOneMain {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\t\r\n\t\tTxn txn = buildDemoTransaction();\r\n\t\t\r\n\t\tSessionFactory sessionFactory = null;\r\n\t\tSession session = null;\r\n\t\tTransaction tx = null;\r\n\t\ttry{\r\n\t\t\/\/Get Session\r\n\t\tsessionFactory = HibernateUtil.getSessionFactory();\r\n\t\tsession = sessionFactory.getCurrentSession();\r\n\t\tSystem.out.println(\"Session created\");\r\n\t\t\/\/start transaction\r\n\t\ttx = session.beginTransaction();\r\n\t\t\/\/Save the Model object\r\n\t\tsession.save(txn);\r\n\t\t\/\/Commit transaction\r\n\t\ttx.commit();\r\n\t\tSystem.out.println(\"Transaction ID=\"+txn.getId());\r\n\t\t\r\n\t\t\/\/Get Saved Trasaction Data\r\n\t\tprintTransactionData(txn.getId(), sessionFactory);\r\n\t\t\r\n\t\t}catch(Exception e){\r\n\t\t\tSystem.out.println(\"Exception occured. \"+e.getMessage());\r\n\t\t\te.printStackTrace();\r\n\t\t}finally{\r\n\t\t\tif(!sessionFactory.isClosed()){\r\n\t\t\t\tSystem.out.println(\"Closing SessionFactory\");\r\n\t\t\t\tsessionFactory.close();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tprivate static void printTransactionData(long id, SessionFactory sessionFactory) {\r\n\t\tSession session = null;\r\n\t\tTransaction tx = null;\r\n\t\ttry{\r\n\t\t\t\/\/Get Session\r\n\t\t\tsessionFactory = HibernateUtil.getSessionFactory();\r\n\t\t\tsession = sessionFactory.getCurrentSession();\r\n\t\t\t\/\/start transaction\r\n\t\t\ttx = session.beginTransaction();\r\n\t\t\t\/\/Save the Model object\r\n\t\t\tTxn txn = (Txn) session.get(Txn.class, id);\r\n\t\t\t\/\/Commit transaction\r\n\t\t\ttx.commit();\r\n\t\t\tSystem.out.println(\"Transaction Details=\\n\"+txn);\r\n\t\t\t\r\n\t\t\t}catch(Exception e){\r\n\t\t\t\tSystem.out.println(\"Exception occured. \"+e.getMessage());\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t}\r\n\r\n\tprivate static Txn buildDemoTransaction() {\r\n\t\tTxn txn = new Txn();\r\n\t\ttxn.setDate(new Date());\r\n\t\ttxn.setTotal(100);\r\n\t\t\r\n\t\tCustomer cust = new Customer();\r\n\t\tcust.setAddress(\"Bangalore, India\");\r\n\t\tcust.setEmail(\"pankaj@gmail.com\");\r\n\t\tcust.setName(\"Pankaj Kumar\");\r\n\t\t\r\n\t\ttxn.setCustomer(cust);\r\n\t\t\r\n\t\tcust.setTxn(txn);\r\n\t\treturn txn;\r\n\t}\r\n\r\n}\r\n<\/code><\/pre>\n<p>\u73b0\u5728\u5f53\u6211\u4eec\u5728Hibernate\u6d4b\u8bd5\u7a0b\u5e8f\u4e2d\u8fd0\u884c\u4ee5\u4e0a\u4e00\u5bf9\u4e00\u7684\u6620\u5c04\u65f6\uff0c\u6211\u4eec\u5f97\u5230\u4ee5\u4e0b\u8f93\u51fa\u7ed3\u679c\u3002<\/p>\n<pre class=\"post-pre\"><code>Hibernate Configuration loaded\r\nHibernate serviceRegistry created\r\nSession created\r\nHibernate: insert into TRANSACTION (txn_date, txn_total) values (?, ?)\r\nHibernate: insert into CUSTOMER (cust_name, cust_email, cust_address, txn_id) values (?, ?, ?, ?)\r\nTransaction ID=19\r\nHibernate: select txn0_.txn_id as txn_id1_1_0_, txn0_.txn_date as txn_date2_1_0_, txn0_.txn_total as txn_tota3_1_0_, \r\ncustomer1_.txn_id as txn_id1_0_1_, customer1_.cust_name as cust_nam2_0_1_, customer1_.cust_email as cust_ema3_0_1_, \r\ncustomer1_.cust_address as cust_add4_0_1_ from TRANSACTION txn0_ left outer join CUSTOMER customer1_ on \r\ntxn0_.txn_id=customer1_.txn_id where txn0_.txn_id=?\r\nTransaction Details=\r\n19, 100.0, Pankaj Kumar, pankaj@gmail.com, Bangalore, India\r\nClosing SessionFactory\r\n<\/code><\/pre>\n<p>\u4f60\u53ef\u4ee5\u770b\u5230\uff0c\u5b83\u8fd0\u884c\u6b63\u5e38\uff0c\u6211\u4eec\u80fd\u591f\u4f7f\u7528\u4e8b\u52a1ID\u4ece\u4e24\u4e2a\u8868\u4e2d\u68c0\u7d22\u6570\u636e\u3002\u67e5\u770bHibernate\u5185\u90e8\u4f7f\u7528\u7684SQL\u6765\u83b7\u53d6\u6570\u636e\u65f6\uff0c\u5b83\u4f7f\u7528\u4e86\u8fde\u63a5\u64cd\u4f5c\u6765\u4ece\u4e24\u4e2a\u8868\u4e2d\u83b7\u53d6\u6570\u636e\u3002<\/p>\n<h2>\u5728\u4e2d\u56fd\u7684\u672c\u5730\u5316\u7ffb\u8bd1\u4e2d\uff0c\u4e00\u5bf9\u4e00\u6620\u5c04\u6ce8\u89e3\u4f1a\u88ab\u7ffb\u8bd1\u4e3a &#8220;Hibernate\u4e00\u5bf9\u4e00\u6620\u5c04\u6ce8\u89e3&#8221;\u3002<\/h2>\n<p>\u5728\u4e0a\u9762\u7684\u90e8\u5206\u4e2d\uff0c\u6211\u4eec\u770b\u5230\u4e86\u5982\u4f55\u4f7f\u7528\u57fa\u4e8eXML\u7684\u914d\u7f6e\u6765\u8fdb\u884cHibernate\u7684\u4e00\u5bf9\u4e00\u6620\u5c04\uff0c\u73b0\u5728\u8ba9\u6211\u4eec\u770b\u770b\u5982\u4f55\u4f7f\u7528JPA\u548cHibernate\u6ce8\u89e3\u6765\u5b9e\u73b0\u540c\u6837\u7684\u529f\u80fd\u3002<\/p>\n<h3>Hibernate \u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>hibernate-annotation.cfg.xml\u7ffb\u8bd1\u4e3a\u4e2d\u6587<\/p>\n<pre class=\"post-pre\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;!DOCTYPE hibernate-configuration PUBLIC\r\n\t\t\"-\/\/Hibernate\/Hibernate Configuration DTD 3.0\/\/EN\"\r\n\t\t\"https:\/\/hibernate.org\/dtd\/hibernate-configuration-3.0.dtd\"&gt;\r\n&lt;hibernate-configuration&gt;\r\n    &lt;session-factory&gt;\r\n        &lt;property name=\"hibernate.connection.driver_class\"&gt;com.mysql.jdbc.Driver&lt;\/property&gt;\r\n        &lt;property name=\"hibernate.connection.password\"&gt;pankaj123&lt;\/property&gt;\r\n        &lt;property name=\"hibernate.connection.url\"&gt;jdbc:mysql:\/\/localhost\/TestDB&lt;\/property&gt;\r\n        &lt;property name=\"hibernate.connection.username\"&gt;pankaj&lt;\/property&gt;\r\n        &lt;property name=\"hibernate.dialect\"&gt;org.hibernate.dialect.MySQLDialect&lt;\/property&gt;\r\n        \r\n        &lt;property name=\"hibernate.current_session_context_class\"&gt;thread&lt;\/property&gt;\r\n        &lt;property name=\"hibernate.show_sql\"&gt;true&lt;\/property&gt;\r\n        \r\n        &lt;mapping class=\"com.Olivia.hibernate.model.Txn1\"\/&gt;\r\n        &lt;mapping class=\"com.Olivia.hibernate.model.Customer1\"\/&gt;\r\n    &lt;\/session-factory&gt;\r\n&lt;\/hibernate-configuration&gt;\r\n<\/code><\/pre>\n<p>Hibernate\u7684\u914d\u7f6e\u975e\u5e38\u7b80\u5355\uff0c\u5c31\u50cf\u4f60\u53ef\u4ee5\u770b\u5230\u7684\u90a3\u6837\uff0c\u6211\u6709\u4e24\u4e2a\u5e26\u6709\u6ce8\u89e3\u7684\u6a21\u578b\u7c7b &#8211; Txn1\u548cCustomer1\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u5b83\u4eec\u3002<\/p>\n<h3>Hibernate\u4e00\u5bf9\u4e00\u6620\u5c04\u6ce8\u91ca\u793a\u4f8b\u6a21\u578b\u7c7b<\/h3>\n<p>\u5c31\u4e00\u5bf9\u4e00\u6620\u5c04\u7684\u6ce8\u89e3\u914d\u7f6e\u800c\u8a00\uff0c\u6a21\u578b\u7c7b\u662f\u6700\u91cd\u8981\u7684\u90e8\u5206\u3002\u8ba9\u6211\u4eec\u770b\u770b\u6211\u4eec\u7684\u6a21\u578b\u7c7b\u5982\u4f55\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.Olivia.hibernate.model;\r\n\r\nimport java.util.Date;\r\n\r\nimport javax.persistence.Column;\r\nimport javax.persistence.Entity;\r\nimport javax.persistence.GeneratedValue;\r\nimport javax.persistence.GenerationType;\r\nimport javax.persistence.Id;\r\nimport javax.persistence.OneToOne;\r\nimport javax.persistence.Table;\r\n\r\nimport org.hibernate.annotations.Cascade;\r\n\r\n@Entity\r\n@Table(name=\"TRANSACTION\")\r\npublic class Txn1 {\r\n\r\n\t@Id\r\n\t@GeneratedValue(strategy=GenerationType.IDENTITY)\r\n\t@Column(name=\"txn_id\")\r\n\tprivate long id;\r\n\t\r\n\t@Column(name=\"txn_date\")\r\n\tprivate Date date;\r\n\t\r\n\t@Column(name=\"txn_total\")\r\n\tprivate double total;\r\n\t\r\n\t@OneToOne(mappedBy=\"txn\")\r\n\t@Cascade(value=org.hibernate.annotations.CascadeType.SAVE_UPDATE)\r\n\tprivate Customer1 customer;\r\n\t\r\n\t@Override\r\n\tpublic String toString(){\r\n\t\treturn id+\", \"+total+\", \"+customer.getName()+\", \"+customer.getEmail()+\", \"+customer.getAddress();\r\n\t}\r\n\r\n        \/\/Getter-Setter methods, omitted for clarity \r\n}\r\n<\/code><\/pre>\n<p>\u8bf7\u6ce8\u610f\uff0c\u5927\u90e8\u5206\u7684\u6ce8\u89e3\u90fd\u662f\u6765\u81ea\u4e8eJava\u6301\u4e45\u5316API\uff0c\u56e0\u4e3aHibernate\u63d0\u4f9b\u4e86\u5b83\u7684\u5b9e\u73b0\u3002\u7136\u800c\uff0c\u5982\u679c\u6211\u4eec\u9700\u8981\u8fdb\u884c\u7ea7\u8054\u64cd\u4f5c\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528Hibernate\u7684\u6ce8\u89e3org.hibernate.annotations.Cascade\u548c\u679a\u4e3eorg.hibernate.annotations.CascadeType\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.Olivia.hibernate.model;\r\n\r\nimport javax.persistence.Column;\r\nimport javax.persistence.Entity;\r\nimport javax.persistence.GeneratedValue;\r\nimport javax.persistence.Id;\r\nimport javax.persistence.OneToOne;\r\nimport javax.persistence.PrimaryKeyJoinColumn;\r\nimport javax.persistence.Table;\r\n\r\nimport org.hibernate.annotations.GenericGenerator;\r\nimport org.hibernate.annotations.Parameter;\r\n\r\n@Entity\r\n@Table(name=\"CUSTOMER\")\r\npublic class Customer1 {\r\n\r\n\t@Id\r\n\t@Column(name=\"txn_id\", unique=true, nullable=false)\r\n\t@GeneratedValue(generator=\"gen\")\r\n\t@GenericGenerator(name=\"gen\", strategy=\"foreign\", parameters={@Parameter(name=\"property\", value=\"txn\")})\r\n\tprivate long id;\r\n\t\r\n\t@Column(name=\"cust_name\")\r\n\tprivate String name;\r\n\t\r\n\t@Column(name=\"cust_email\")\r\n\tprivate String email;\r\n\t\r\n\t@Column(name=\"cust_address\")\r\n\tprivate String address;\r\n\t\r\n\t@OneToOne\r\n\t@PrimaryKeyJoinColumn\r\n\tprivate Txn1 txn;\r\n\r\n        \/\/Getter-Setter methods\r\n}\r\n<\/code><\/pre>\n<p>\u8bf7\u6ce8\u610f\uff0c\u6211\u4eec\u9700\u8981\u6dfb\u52a0@GenericGenerator\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u4f7f\u7528\u4e8b\u52a1\u4e2d\u7684id\u800c\u4e0d\u662f\u751f\u6210\u4e00\u4e2a\u65b0\u7684id\u3002<\/p>\n<h3>Hibernate SessionFactory \u5b9e\u7528\u5de5\u5177\u7c7b<\/h3>\n<p>\u521b\u5efaSessionFactory\u4e0e\u6211\u4eec\u63d0\u4f9b\u7684Hibernate\u6620\u5c04\u65b9\u5f0f\u65e0\u5173\u3002\u6211\u4eec\u7528\u4e8e\u521b\u5efaSessionFactory\u7684\u5b9e\u7528\u7c7b\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.Olivia.hibernate.util;\r\n\r\nimport org.hibernate.SessionFactory;\r\nimport org.hibernate.boot.registry.StandardServiceRegistryBuilder;\r\nimport org.hibernate.cfg.Configuration;\r\nimport org.hibernate.service.ServiceRegistry;\r\n\r\npublic class HibernateAnnotationUtil {\r\n\r\n\tprivate static SessionFactory sessionFactory;\r\n\t\r\n\tprivate static SessionFactory buildSessionFactory() {\r\n        try {\r\n            \/\/ Create the SessionFactory from hibernate-annotation.cfg.xml\r\n        \tConfiguration configuration = new Configuration();\r\n        \tconfiguration.configure(\"hibernate-annotation.cfg.xml\");\r\n        \tSystem.out.println(\"Hibernate Annotation Configuration loaded\");\r\n        \t\r\n        \tServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();\r\n        \tSystem.out.println(\"Hibernate Annotation serviceRegistry created\");\r\n        \t\r\n        \tSessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);\r\n        \t\r\n            return sessionFactory;\r\n        }\r\n        catch (Throwable ex) {\r\n            System.err.println(\"Initial SessionFactory creation failed.\" + ex);\r\n            ex.printStackTrace();\r\n            throw new ExceptionInInitializerError(ex);\r\n        }\r\n    }\r\n\t\r\n\tpublic static SessionFactory getSessionFactory() {\r\n\t\tif(sessionFactory == null) sessionFactory = buildSessionFactory();\r\n        return sessionFactory;\r\n    }\r\n}\r\n<\/code><\/pre>\n<h3>Hibernate\u4e00\u5bf9\u4e00\u6620\u5c04\u6ce8\u91ca\u793a\u4f8b\u6d4b\u8bd5\u7a0b\u5e8f<\/h3>\n<p>\u8fd9\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u6d4b\u8bd5\u7a0b\u5e8f\uff0c\u7528\u4e8e\u6211\u4eec\u7684Hibernate\u4e00\u5bf9\u4e00\u6620\u5c04\u6ce8\u89e3\u793a\u4f8b\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.Olivia.hibernate.main;\r\n\r\nimport java.util.Date;\r\n\r\nimport org.hibernate.Session;\r\nimport org.hibernate.SessionFactory;\r\nimport org.hibernate.Transaction;\r\n\r\nimport com.Olivia.hibernate.model.Customer1;\r\nimport com.Olivia.hibernate.model.Txn1;\r\nimport com.Olivia.hibernate.util.HibernateAnnotationUtil;\r\n\r\npublic class HibernateOneToOneAnnotationMain {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\t\r\n\t\tTxn1 txn = buildDemoTransaction();\r\n\t\t\r\n\t\tSessionFactory sessionFactory = null;\r\n\t\tSession session = null;\r\n\t\tTransaction tx = null;\r\n\t\ttry{\r\n\t\t\/\/Get Session\r\n\t\tsessionFactory = HibernateAnnotationUtil.getSessionFactory();\r\n\t\tsession = sessionFactory.getCurrentSession();\r\n\t\tSystem.out.println(\"Session created using annotations configuration\");\r\n\t\t\/\/start transaction\r\n\t\ttx = session.beginTransaction();\r\n\t\t\/\/Save the Model object\r\n\t\tsession.save(txn);\r\n\t\t\/\/Commit transaction\r\n\t\ttx.commit();\r\n\t\tSystem.out.println(\"Annotation Example. Transaction ID=\"+txn.getId());\r\n\t\t\r\n\t\t\/\/Get Saved Trasaction Data\r\n\t\tprintTransactionData(txn.getId(), sessionFactory);\r\n\t\t}catch(Exception e){\r\n\t\t\tSystem.out.println(\"Exception occured. \"+e.getMessage());\r\n\t\t\te.printStackTrace();\r\n\t\t}finally{\r\n\t\t\tif(sessionFactory != null &amp;&amp; !sessionFactory.isClosed()){\r\n\t\t\t\tSystem.out.println(\"Closing SessionFactory\");\r\n\t\t\t\tsessionFactory.close();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tprivate static void printTransactionData(long id, SessionFactory sessionFactory) {\r\n\t\tSession session = null;\r\n\t\tTransaction tx = null;\r\n\t\ttry{\r\n\t\t\t\/\/Get Session\r\n\t\t\tsessionFactory = HibernateAnnotationUtil.getSessionFactory();\r\n\t\t\tsession = sessionFactory.getCurrentSession();\r\n\t\t\t\/\/start transaction\r\n\t\t\ttx = session.beginTransaction();\r\n\t\t\t\/\/Save the Model object\r\n\t\t\tTxn1 txn = (Txn1) session.get(Txn1.class, id);\r\n\t\t\t\/\/Commit transaction\r\n\t\t\ttx.commit();\r\n\t\t\tSystem.out.println(\"Annotation Example. Transaction Details=\\n\"+txn);\r\n\t\t\t\r\n\t\t\t}catch(Exception e){\r\n\t\t\t\tSystem.out.println(\"Exception occured. \"+e.getMessage());\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t}\r\n\r\n\tprivate static Txn1 buildDemoTransaction() {\r\n\t\tTxn1 txn = new Txn1();\r\n\t\ttxn.setDate(new Date());\r\n\t\ttxn.setTotal(100);\r\n\t\t\r\n\t\tCustomer1 cust = new Customer1();\r\n\t\tcust.setAddress(\"San Jose, USA\");\r\n\t\tcust.setEmail(\"pankaj@yahoo.com\");\r\n\t\tcust.setName(\"Pankaj Kr\");\r\n\t\t\r\n\t\ttxn.setCustomer(cust);\r\n\t\t\r\n\t\tcust.setTxn(txn);\r\n\t\treturn txn;\r\n\t}\r\n\r\n}\r\n<\/code><\/pre>\n<p>\u5728\u6267\u884c\u4ee5\u4e0a\u7a0b\u5e8f\u65f6\uff0c\u8fd9\u662f\u8f93\u51fa\u7247\u6bb5\u3002<\/p>\n<pre class=\"post-pre\"><code>Hibernate Annotation Configuration loaded\r\nHibernate Annotation serviceRegistry created\r\nSession created using annotations configuration\r\nHibernate: insert into TRANSACTION (txn_date, txn_total) values (?, ?)\r\nHibernate: insert into CUSTOMER (cust_address, cust_email, cust_name, txn_id) values (?, ?, ?, ?)\r\nAnnotation Example. Transaction ID=20\r\nHibernate: select txn1x0_.txn_id as txn_id1_1_0_, txn1x0_.txn_date as txn_date2_1_0_, txn1x0_.txn_total as txn_tota3_1_0_, \r\ncustomer1x1_.txn_id as txn_id1_0_1_, customer1x1_.cust_address as cust_add2_0_1_, customer1x1_.cust_email as cust_ema3_0_1_, \r\ncustomer1x1_.cust_name as cust_nam4_0_1_ from TRANSACTION txn1x0_ left outer join CUSTOMER customer1x1_ on \r\ntxn1x0_.txn_id=customer1x1_.txn_id where txn1x0_.txn_id=?\r\nAnnotation Example. Transaction Details=\r\n20, 100.0, Pankaj Kr, pankaj@yahoo.com, San Jose, USA\r\nClosing SessionFactory\r\n<\/code><\/pre>\n<p>\u8bf7\u6ce8\u610f\uff0c\u8f93\u51fa\u7ed3\u679c\u4e0eHibernate\u4e00\u5bf9\u4e00\u7684\u57fa\u4e8eXML\u7684\u914d\u7f6e\u7c7b\u4f3c\u3002\u81f3\u6b64\uff0cHibernate\u4e00\u5bf9\u4e00\u6620\u5c04\u793a\u4f8b\u4ecb\u7ecd\u5b8c\u6bd5\uff0c\u60a8\u53ef\u4ee5\u4ece\u4e0b\u65b9\u94fe\u63a5\u4e0b\u8f7d\u6700\u7ec8\u9879\u76ee\u5e76\u8fdb\u884c\u5b9e\u8df5\uff0c\u4ee5\u4fbf\u66f4\u591a\u5b66\u4e60\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u6211\u4eec\u5c06\u5b66\u4e60Hibernate\u4e2d\u7684\u4e00\u5bf9\u4e00\u6620\u5c04\u3002\u6211\u4eec\u5c06\u4ecb\u7ecd\u4f7f\u7528\u6ce8\u89e3\u548cXML\u914d\u7f6e\u7684Hibernate\u4e00\u5bf9\u4e00\u6620\u5c04\u793a [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-50730","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u6ce8\u89e3\u7684\u793a\u4f8b\uff1aHibernate\u4e00\u5bf9\u4e00\u6620\u5c04 - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u6ce8\u89e3\u7684\u793a\u4f8b\uff1ahibernate\u4e00\u5bf9\u4e00\u6620\u5c04\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u6ce8\u89e3\u7684\u793a\u4f8b\uff1aHibernate\u4e00\u5bf9\u4e00\u6620\u5c04\" \/>\n<meta property=\"og:description\" content=\"\u4eca\u5929\u6211\u4eec\u5c06\u5b66\u4e60Hibernate\u4e2d\u7684\u4e00\u5bf9\u4e00\u6620\u5c04\u3002\u6211\u4eec\u5c06\u4ecb\u7ecd\u4f7f\u7528\u6ce8\u89e3\u548cXML\u914d\u7f6e\u7684Hibernate\u4e00\u5bf9\u4e00\u6620\u5c04\u793a [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u6ce8\u89e3\u7684\u793a\u4f8b\uff1ahibernate\u4e00\u5bf9\u4e00\u6620\u5c04\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-12-23T02:31:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-23T07:32:43+00:00\" \/>\n<meta name=\"author\" content=\"\u9038, \u79d1\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u9038, \u79d1\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%b3%a8%e8%a7%a3%e7%9a%84%e7%a4%ba%e4%be%8b%ef%bc%9ahibernate%e4%b8%80%e5%af%b9%e4%b8%80%e6%98%a0%e5%b0%84\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%b3%a8%e8%a7%a3%e7%9a%84%e7%a4%ba%e4%be%8b%ef%bc%9ahibernate%e4%b8%80%e5%af%b9%e4%b8%80%e6%98%a0%e5%b0%84\/\",\"name\":\"\u6ce8\u89e3\u7684\u793a\u4f8b\uff1aHibernate\u4e00\u5bf9\u4e00\u6620\u5c04 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-12-23T02:31:39+00:00\",\"dateModified\":\"2023-12-23T07:32:43+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/85c1dae56e6ea1e695c73d33c684d487\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%b3%a8%e8%a7%a3%e7%9a%84%e7%a4%ba%e4%be%8b%ef%bc%9ahibernate%e4%b8%80%e5%af%b9%e4%b8%80%e6%98%a0%e5%b0%84\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%b3%a8%e8%a7%a3%e7%9a%84%e7%a4%ba%e4%be%8b%ef%bc%9ahibernate%e4%b8%80%e5%af%b9%e4%b8%80%e6%98%a0%e5%b0%84\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%b3%a8%e8%a7%a3%e7%9a%84%e7%a4%ba%e4%be%8b%ef%bc%9ahibernate%e4%b8%80%e5%af%b9%e4%b8%80%e6%98%a0%e5%b0%84\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u6ce8\u89e3\u7684\u793a\u4f8b\uff1aHibernate\u4e00\u5bf9\u4e00\u6620\u5c04\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/85c1dae56e6ea1e695c73d33c684d487\",\"name\":\"\u9038, \u79d1\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c94f6d9cbbfbca863fab309840bd690c153c95f8490c290ad2ed54dd693dad16?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c94f6d9cbbfbca863fab309840bd690c153c95f8490c290ad2ed54dd693dad16?s=96&d=mm&r=g\",\"caption\":\"\u9038, \u79d1\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/keyi\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%b3%a8%e8%a7%a3%e7%9a%84%e7%a4%ba%e4%be%8b%ef%bc%9ahibernate%e4%b8%80%e5%af%b9%e4%b8%80%e6%98%a0%e5%b0%84\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u6ce8\u89e3\u7684\u793a\u4f8b\uff1aHibernate\u4e00\u5bf9\u4e00\u6620\u5c04 - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u6ce8\u89e3\u7684\u793a\u4f8b\uff1ahibernate\u4e00\u5bf9\u4e00\u6620\u5c04\/","og_locale":"zh_CN","og_type":"article","og_title":"\u6ce8\u89e3\u7684\u793a\u4f8b\uff1aHibernate\u4e00\u5bf9\u4e00\u6620\u5c04","og_description":"\u4eca\u5929\u6211\u4eec\u5c06\u5b66\u4e60Hibernate\u4e2d\u7684\u4e00\u5bf9\u4e00\u6620\u5c04\u3002\u6211\u4eec\u5c06\u4ecb\u7ecd\u4f7f\u7528\u6ce8\u89e3\u548cXML\u914d\u7f6e\u7684Hibernate\u4e00\u5bf9\u4e00\u6620\u5c04\u793a [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u6ce8\u89e3\u7684\u793a\u4f8b\uff1ahibernate\u4e00\u5bf9\u4e00\u6620\u5c04\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-12-23T02:31:39+00:00","article_modified_time":"2023-12-23T07:32:43+00:00","author":"\u9038, \u79d1","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u9038, \u79d1","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%b3%a8%e8%a7%a3%e7%9a%84%e7%a4%ba%e4%be%8b%ef%bc%9ahibernate%e4%b8%80%e5%af%b9%e4%b8%80%e6%98%a0%e5%b0%84\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%b3%a8%e8%a7%a3%e7%9a%84%e7%a4%ba%e4%be%8b%ef%bc%9ahibernate%e4%b8%80%e5%af%b9%e4%b8%80%e6%98%a0%e5%b0%84\/","name":"\u6ce8\u89e3\u7684\u793a\u4f8b\uff1aHibernate\u4e00\u5bf9\u4e00\u6620\u5c04 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-12-23T02:31:39+00:00","dateModified":"2023-12-23T07:32:43+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/85c1dae56e6ea1e695c73d33c684d487"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%b3%a8%e8%a7%a3%e7%9a%84%e7%a4%ba%e4%be%8b%ef%bc%9ahibernate%e4%b8%80%e5%af%b9%e4%b8%80%e6%98%a0%e5%b0%84\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e6%b3%a8%e8%a7%a3%e7%9a%84%e7%a4%ba%e4%be%8b%ef%bc%9ahibernate%e4%b8%80%e5%af%b9%e4%b8%80%e6%98%a0%e5%b0%84\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%b3%a8%e8%a7%a3%e7%9a%84%e7%a4%ba%e4%be%8b%ef%bc%9ahibernate%e4%b8%80%e5%af%b9%e4%b8%80%e6%98%a0%e5%b0%84\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u6ce8\u89e3\u7684\u793a\u4f8b\uff1aHibernate\u4e00\u5bf9\u4e00\u6620\u5c04"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/85c1dae56e6ea1e695c73d33c684d487","name":"\u9038, \u79d1","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c94f6d9cbbfbca863fab309840bd690c153c95f8490c290ad2ed54dd693dad16?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c94f6d9cbbfbca863fab309840bd690c153c95f8490c290ad2ed54dd693dad16?s=96&d=mm&r=g","caption":"\u9038, \u79d1"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/keyi\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%b3%a8%e8%a7%a3%e7%9a%84%e7%a4%ba%e4%be%8b%ef%bc%9ahibernate%e4%b8%80%e5%af%b9%e4%b8%80%e6%98%a0%e5%b0%84\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/50730","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=50730"}],"version-history":[{"count":1,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/50730\/revisions"}],"predecessor-version":[{"id":50801,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/50730\/revisions\/50801"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=50730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=50730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=50730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}