{"id":523,"date":"2017-04-07T15:35:21","date_gmt":"2017-04-07T07:35:21","guid":{"rendered":"http:\/\/www.mrtblog.cn\/?p=523"},"modified":"2023-03-04T19:28:06","modified_gmt":"2023-03-04T11:28:06","slug":"springhibernatemysql%e5%bc%80%e5%8f%91%e5%b8%b8%e8%a7%81%e9%97%ae%e9%a2%98%e8%ae%b0%e5%bd%95","status":"publish","type":"post","link":"http:\/\/www.mrtblog.cn\/?p=523","title":{"rendered":"Spring+Hibernate+Mysql\u5f00\u53d1\u5e38\u89c1\u95ee\u9898\u8bb0\u5f55"},"content":{"rendered":"<div class='epvc-post-count'><span class='epvc-eye'><\/span>  <span class=\"epvc-count\"> 1,733<\/span><span class='epvc-label'> Views<\/span><\/div><p>\u597d\u5427\uff0c\u53c8\u5f00\u65b0\u5751\uff0c\u672c\u6765\u5bf9spring mvc\u6846\u67b6\u5f88\u4e0d\u719f\uff0c\u5ffd\u7136\u88ab\u62c9\u6765\u505a\u7cfb\u7edf\u5f00\u53d1\uff0c\u4ee5\u6b64\u6587\u8bb0\u5f55\u9047\u5230\u7684\u5404\u79cd\u5f02\u5e38\uff0c\u540c\u65f6\u5b66\u4e60mis\u7cfb\u7edf\u5f00\u53d1\u3002<strong><br \/>\n<!--StartFragment --><\/strong><\/p>\n<h4>1. not-null&nbsp;property&nbsp;references&nbsp;a&nbsp;null&nbsp;or&nbsp;transient&nbsp;value<\/h4>\n<p>\u4f7f\u7528hibernate\u5efa\u7acbmysql\u8868\u6709\u4e09\u79cd\u65b9\u5f0f\uff0c\u6bd4\u8f83\u7b80\u5355\u7684\u4e3a\u5efa\u7acbJava\u7c7b\uff0c\u4f7f\u7528hibernate\u76f4\u63a5\u5efa\u8868\uff08\u4e0d\u9700\u8981mysql\u5efa\u8868\uff09\u3002<\/p>\n<p>\u6bd4\u5982\u6709\u4e24\u4e2a\u7c7bA\u3001B\u5bf9\u5e94\u8868tA\uff0ctB\uff0c\u540c\u65f6A\u7c7b\u4e2d\u6210\u5458\u5305\u542bB\u7c7b\u7684\u5bf9\u8c61,\u5373\uff1a<\/p>\n<pre class=\"highlight\"><code class=\"language-java line-numbers\">\npublic class A{\n    @Id\n    @GeneratedValue\n    private Long id;\/\/\u5e8f\u53f7\n\n    @Column(length=200,nullable=false,unique=true)\n    private String name;\/\/\u540d\u5b57\n\n    @ManyToOne(optional=false)\n    private B b;\ngetter and setter...\n}<\/code><\/pre>\n<p>\u5411A\u8868\u505a\u66f4\u6539\u65f6\uff0c\u5982\u679c\u6ca1\u6709\u5bf9A\u4e2d\u6210\u5458b\u8d4b\u521d\u503c\u6216\u672a\u5f15\u7528\u7c7bB\u7684\u5bf9\u8c61\u4e14\u7c7bA\u4e2db\u6210\u5458\u4e0d\u80fd\u4e3a\u7a7a\uff0c\u5219\u4f1a\u51fa\u73b0\u6b64\u9519\u8bef\u3002\u5373\u4f7f\u624b\u52a8\u751f\u6210B\u7684\u5bf9\u8c61b0\uff0c\u6267\u884cA.setB(b0)\uff0cb0\u4e0d\u662f\u4ece\u6570\u636e\u5e93\u4e2d\u53d6\u51fa\u7684\u6570\u636e\u751f\u6210\u7684\u5bf9\u8c61\uff0c\u4e5f\u4f1a\u51fa\u73b0\u6b64\u9519\u8bef\u3002\u4e2a\u4eba\u89c9\u5f97\u5e94\u5f53\u51cf\u5c11\u8fd9\u79cd\u4f9d\u8d56\u5173\u7cfb\uff0c\u5728A\u7c7b\u4e2d\u53ef\u4ee5\u7528B\u7c7b\u7684id\u7b49\u552f\u4e00\u6807\u8bc6\u4f5c\u4e3a\u7d22\u5f15\u5efa\u7acb\u5173\u8054\u3002<\/p>\n<hr>\n<h4>2.java.lang.AbstractMethodError: Method org\/apache\/commons\/dbcp\/DelegatingPreparedStatement.setCharacterStream(ILjava\/io\/Reader;J)V is abstract<\/h4>\n<p>\u5bf9\u7b80\u5355\u7528\u4f8bbookshop\u505a\u66f4\u6539\u540e\uff0c\u5c06Category\u7c7b\u66ff\u6362\u6210Users\u7c7b\uff0c\u9664\u4e86\u7c7b\u4e2d\u65b9\u6cd5\u7565\u6709\u4e0d\u540c\u4ee5\u53ca\u7c7b\u540d\u4ee5\u5916\u6ca1\u6709\u4efb\u4f55\u5dee\u522b\uff0c\u7136\u800c\u66ff\u6362\u540e\u62a5\u4e0a\u8ff0\u9519\u8bef\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\u5f88\u7b80\u5355\uff0c\u53ea\u8981\u628a\u76f8\u5173\u4f9d\u8d56commons-dbcp\u7248\u672c\u6539\u62101.4\u5373\u53ef\uff08\u539f\u6765\u4f7f\u7528\u7684\u662f2003\u7248\u672c\uff09<\/p>\n<h4>3.\u4f7f\u7528spring+hibernate+ajax\u524d\u540e\u7aef\u901a\u8baf\u65f6\u65e0\u6cd5\u83b7\u53d6\u6570\u636e<\/h4>\n<p>\u5e38\u89c1\u7684\u9519\u8bef\u6709\u51e0\u4e2a\uff1a<\/p>\n<p>404\u9519\u8bef\uff1aajax\u8bbf\u95ee\u7684\u5730\u5740\u548cspring\u6620\u5c04\u7684\u5730\u5740\u4e0d\u5339\u914d<\/p>\n<p>400\u9519\u8bef\uff1aajax\u4f20\u9012\u7684\u53c2\u6570\u548cspringcontroller\u63a5\u53d7\u53c2\u6570\u4e0d\u5339\u914d\uff08\u5c24\u5176\u662f\u4f20\u9012\u5bf9\u8c61\u65f6\u4f1a\u51fa\u73b0\u8f83\u591a\u95ee\u9898\uff09\uff0c\u5982\u679c\u4f20\u591a\u4e2a\u5bf9\u8c61\uff0c\u8fd9\u4e9b\u5bf9\u8c61\u7684\u5c5e\u6027\u6709\u540c\u540d\u60c5\u51b5\uff0c\u5c31\u5fc5\u987b\u5206\u5f00\u4f7f\u7528\u522b\u540d\u4f20\u8f93\uff0c\u7136\u540e\u5728controller\u5c42\u505a\u4e00\u6b21\u5bf9\u8c61\u5c01\u88c5\uff0c\u518d\u4ea4\u7ed9service<\/p>\n<p>500\u9519\u8bef\uff1a\u5f88\u83ab\u540d\u7684\u9519\u8bef<\/p>\n<p>\u6ca1\u6709\u9519\u8bef\uff1a\u9047\u5230\u7684\u6700\u5934\u75bc\u7684\u662f\u524d\u7aef\u4e0d\u62a5\u9519\uff0c\u540e\u7aef\u4e0d\u62a5\u9519\uff0cdebug\u4e0d\u62a5\u9519\uff0c\u4f46\u662f\u6570\u636e\u5c31\u662f\u4f20\u4e0d\u8fc7\u6765\uff0c\u600e\u4e48\u4f20\u90fd\u662f\u7a7a<br \/>\nspring+hibernate\u4ece\u6570\u636e\u5e93\u83b7\u53d6\u8868\u7684\u8bb0\u5f55\uff0c\u5e76\u6309\u7167\u5b57\u6bb5\u4f9d\u6b21\u8fd4\u56de\u7ed9ajax\u3002<br \/>\ndebug\u8fc7\u7a0b\u4eceservice\u5c42\u5230controller\u5c42\u83b7\u53d6\u5230\u7684\u5b9e\u4f53\u5bf9\u8c61user\u7684\u6240\u6709\u5c5e\u6027\u90fd\u5df2\u7ecf\u83b7\u53d6\u5230\u503c\u4e86\uff0c\u4f46\u662f\u5c06\u5bf9\u8c61\u8f6c\u6362\u4e3ajson\u4f20\u9012\u540e\uff0cajax\u65e0\u6cd5\u63a5\u53d7\u6570\u636e\u7684\u67d0\u4e00\u4e2a\u5b57\u6bb5\uff08\u5176\u4ed6\u5b57\u6bb5\u90fd\u80fd\u63a5\u6536\uff0c\u4f46\u662f\u6709\u4e00\u4e2a\u5b57\u6bb5\u59cb\u7ec8\u4e3a\u7a7a\uff09\uff0c\u53cd\u590d\u7ea0\u7ed3\u4e4b\u540e\u7ecf\u8fc7\u8001\u677f\u63d0\u9192\u624d\u53d1\u73b0\u662fdomain\u5b9e\u4f53\u4e2d\u7684\u8be5\u5b57\u6bb5\u6ca1\u6709\u8bbe\u7f6egetter\u548csetter\u65b9\u6cd5\uff0c\u5bfc\u81f4hibernate\u505a\u5bf9\u8c61\u8f6cjson\u65f6\u65e0\u6cd5\u5bf9\u8be5\u5b57\u6bb5\u8d4b\u503c\uff0c\u4f46\u662f\u5374\u4e0d\u62a5\u9519\u3002\u4ee5\u540e\u503c\u5f97\u6ce8\u610f\u7684\u4e00\u70b9\uff0c\u5b9e\u4f53\u7c7b\u65b0\u5efa\u597d\u540e\u5c31\u8981\u7acb\u523b\u8bbe\u5168getter\u548csetter\u65b9\u6cd5\u3002<\/p>\n<h4>4.\u9879\u76ee\u542f\u52a8\u65f6\u62a5\u9519\uff1a[No Spring WebApplicationInitializer types detected on classpath]<\/h4>\n<p>\u539f\u672c\u9879\u76ee\u505a\u5f97\u597d\u597d\u7684\uff0c\u5ffd\u7136\u67d0\u4e00\u5929\u65e9\u4e0a\uff0c\u5728\u6ca1\u6709\u4efb\u4f55\u6539\u52a8\u7684\u60c5\u51b5\u4e0b\u51fa\u73b0\u6b64\u9519\u8bef\u3002\u7f51\u4e0a\u7684\u89e3\u51b3\u65b9\u684899%\u662f\u9488\u5bf9\u6ca1\u6709\u6b63\u786e\u914d\u7f6eweb.xml\u7684\u3002\u4f46\u662f\u8fd9\u79cd\u9519\u8bef\u56e0\u4e3a\u4e4b\u524d\u8fd0\u884c\u5f97\u597d\u597d\u7684\uff0c\u4e0d\u53ef\u80fd\u662f\u914d\u7f6e\u9519\u8bef\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\uff1a\uff081\uff09\u4f7f\u7528mvn clean\uff082\uff09\u628aspring\u9879\u76ee\u4ecetomcat\u4e2d\u79fb\u9664\uff0c\u518d\u91cd\u65b0\u52a0\u5165\u5373\u53ef\u89e3\u51b3<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1,733 Views\u597d\u5427\uff0c\u53c8\u5f00\u65b0\u5751\uff0c\u672c\u6765\u5bf9spring mvc\u6846\u67b6\u5f88\u4e0d\u719f\uff0c\u5ffd\u7136\u88ab\u62c9\u6765\u505a\u7cfb\u7edf\u5f00\u53d1\uff0c\u4ee5\u6b64\u6587\u8bb0\u5f55\u9047 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[92],"tags":[89,7,90,88],"class_list":["post-523","post","type-post","status-publish","format-standard","hentry","category-project","tag-hibnerate","tag-java","tag-mysql","tag-spring"],"_links":{"self":[{"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=\/wp\/v2\/posts\/523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=523"}],"version-history":[{"count":8,"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=\/wp\/v2\/posts\/523\/revisions"}],"predecessor-version":[{"id":1177,"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=\/wp\/v2\/posts\/523\/revisions\/1177"}],"wp:attachment":[{"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=523"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}