{"id":6886,"date":"2024-11-14T11:25:58","date_gmt":"2024-11-14T03:25:58","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6886\/"},"modified":"2024-11-14T11:25:58","modified_gmt":"2024-11-14T03:25:58","slug":"jpa-%e6%95%b0%e6%8d%ae%e5%ba%93%e9%bb%98%e8%ae%a4%e5%80%bc%e4%b8%ba%e4%bd%95%e5%af%bc%e8%87%b4column-cannot-be-null%e9%94%99%e8%af%af%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6886\/","title":{"rendered":"JPA \u6570\u636e\u5e93\u9ed8\u8ba4\u503c\u4e3a\u4f55\u5bfc\u81f4\u201cColumn cannot be null\u201d\u9519\u8bef\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173001474396190.jpg\" class=\"aligncenter\" title=\"JPA \u6570\u636e\u5e93\u9ed8\u8ba4\u503c\u4e3a\u4f55\u5bfc\u81f4\u201cColumn cannot be null\u201d\u9519\u8bef\uff1f\u63d2\u56fe\" alt=\"JPA \u6570\u636e\u5e93\u9ed8\u8ba4\u503c\u4e3a\u4f55\u5bfc\u81f4\u201cColumn cannot be null\u201d\u9519\u8bef\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>jpa \u6570\u636e\u5e93\u9ed8\u8ba4\u503c\u5f15\u53d1\u201ccolumn cannot be null\u201d\u9519\u8bef<\/strong><\/p>\n<p>\u5728 jpa \u4e2d\uff0c\u6570\u636e\u5e93\u5df2\u8bbe\u7f6e\u9ed8\u8ba4\u503c\u7684\u60c5\u51b5\u4e0b\uff0c\u4fdd\u5b58\u5b9e\u4f53\u5374\u629b\u51fa\u201ccolumn cannot be null\u201d\u5f02\u5e38\uff0c\u539f\u56e0\u53ef\u80fd\u5982\u4e0b\uff1a<\/p>\n<p><strong>\u5168\u91cf\u64cd\u4f5c\u5b57\u6bb5<\/strong><\/p>\n<p>jpa \u9ed8\u8ba4\u4f1a\u5bf9\u6240\u6709\u5b57\u6bb5\u8fdb\u884c\u5168\u91cf\u64cd\u4f5c\uff0c\u5373\u4f7f\u6570\u636e\u5e93\u63d0\u4f9b\u4e86\u9ed8\u8ba4\u503c\u3002\u8fd9\u610f\u5473\u7740\uff0c\u5373\u4f7f\u5b9e\u4f53\u4e2d\u67d0\u5b57\u6bb5\u7684\u503c\u4e3a null\uff0cjpa \u4e5f\u4f1a\u5411\u6570\u636e\u5e93\u63d2\u5165 null \u503c\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a@dynamicinsert \u6ce8\u89e3<\/strong><\/p>\n<p>\u4e3a\u4e86\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\uff0c\u53ef\u4ee5\u5728\u5b9e\u4f53\u7c7b\u4e2d\u4e3a\u6709\u9ed8\u8ba4\u503c\u7684\u5b57\u6bb5\u6dfb\u52a0 @dynamicinsert \u6ce8\u89e3\u3002\u6b64\u6ce8\u89e3\u6307\u793a jpa \u53ea\u63d2\u5165\u975e null \u503c\u7684\u5b57\u6bb5\uff0c\u5141\u8bb8\u6570\u636e\u5e93\u4f7f\u7528\u9ed8\u8ba4\u503c\u586b\u5145\u7a7a\u503c\u5b57\u6bb5\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528 @dynamicinsert \u6ce8\u89e3\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre>@Entity\n@DynamicInsert\npublic class XXX { \n    @Column(name = \"`aaa`\")\n    private String aaa;\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6dfb\u52a0\u6b64\u6ce8\u89e3\u540e\uff0cjpa \u5728\u5411\u6570\u636e\u5e93\u63d2\u5165\u65b0\u5b9e\u4f53\u65f6\uff0c\u5c06\u4ec5\u63d2\u5165\u975e null \u7684\u5b57\u6bb5\u503c\uff0c\u800c aaa \u5b57\u6bb5\u5c06\u4f7f\u7528\u6570\u636e\u5e93\u63d0\u4f9b\u7684\u9ed8\u8ba4\u503c\u586b\u5145\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJPA \u6570\u636e\u5e93\u9ed8\u8ba4\u503c\u4e3a\u4f55\u5bfc\u81f4\u201cColumn cannot be null\u201d\u9519\u8bef\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>jpa \u6570\u636e\u5e93\u9ed8\u8ba4\u503c\u5f15\u53d1\u201ccolumn cannot be null\u201d\u9519\u8bef \u5728 jpa \u4e2d\uff0c\u6570\u636e\u5e93\u5df2\u8bbe\u7f6e\u9ed8\u8ba4\u503c\u7684\u60c5\u51b5\u4e0b\uff0c\u4fdd\u5b58\u5b9e\u4f53\u5374\u629b\u51fa\u201ccolumn cannot be null\u201d\u5f02\u5e38\uff0c\u539f\u56e0\u53ef\u80fd\u5982\u4e0b\uff1a \u5168\u91cf\u64cd\u4f5c\u5b57\u6bb5 jpa \u9ed8\u8ba4\u4f1a\u5bf9\u6240\u6709\u5b57\u6bb5\u8fdb\u884c\u5168\u91cf\u64cd\u4f5c\uff0c\u5373\u4f7f\u6570\u636e\u5e93\u63d0\u4f9b\u4e86\u9ed8\u8ba4\u503c\u3002\u8fd9\u610f\u5473\u7740\uff0c\u5373\u4f7f\u5b9e\u4f53\u4e2d\u67d0\u5b57\u6bb5\u7684\u503c\u4e3a null\uff0cjpa \u4e5f\u4f1a\u5411\u6570\u636e\u5e93\u63d2\u5165 null \u503c\u3002 \u89e3\u51b3\u65b9\u6848\uff1a@dynamicinsert \u6ce8\u89e3 \u4e3a\u4e86\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\uff0c\u53ef\u4ee5\u5728\u5b9e\u4f53\u7c7b\u4e2d\u4e3a\u6709\u9ed8\u8ba4\u503c\u7684\u5b57\u6bb5\u6dfb\u52a0 @dynamicinsert \u6ce8\u89e3\u3002\u6b64\u6ce8\u89e3\u6307\u793a jpa \u53ea\u63d2\u5165\u975e null \u503c\u7684\u5b57\u6bb5\uff0c\u5141\u8bb8\u6570\u636e\u5e93\u4f7f\u7528\u9ed8\u8ba4\u503c\u586b\u5145\u7a7a\u503c\u5b57\u6bb5\u3002 \u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528 @dynamicinsert \u6ce8\u89e3\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u793a\u4f8b\u4ee3\u7801\uff1a @Entity @DynamicInsert public class XXX { @Column(name = &#8220;`aaa`&#8221;) private String aaa; } \u767b\u5f55\u540e\u590d\u5236 \u6dfb\u52a0\u6b64\u6ce8\u89e3\u540e\uff0cjpa \u5728\u5411\u6570\u636e\u5e93\u63d2\u5165\u65b0\u5b9e\u4f53\u65f6\uff0c\u5c06\u4ec5\u63d2\u5165\u975e null \u7684\u5b57\u6bb5\u503c\uff0c\u800c aaa \u5b57\u6bb5\u5c06\u4f7f\u7528\u6570\u636e\u5e93\u63d0\u4f9b\u7684\u9ed8\u8ba4\u503c\u586b\u5145\u3002 \u4ee5\u4e0a\u5c31\u662fJPA \u6570\u636e\u5e93\u9ed8\u8ba4\u503c\u4e3a\u4f55\u5bfc\u81f4\u201cColumn cannot be null\u201d\u9519\u8bef\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6886","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6886","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=6886"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6886\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6886"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}