{"id":6885,"date":"2024-11-14T13:03:42","date_gmt":"2024-11-14T05:03:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6885\/"},"modified":"2024-11-14T13:03:42","modified_gmt":"2024-11-14T05:03:42","slug":"jpa%e4%bf%9d%e5%ad%98%e5%ae%9e%e4%bd%93%e6%8a%a5%e9%94%99column-cannot-be-null%ef%bc%8c%e5%8d%b3%e4%bd%bf%e6%95%b0%e6%8d%ae%e5%ba%93%e6%9c%89%e9%bb%98%e8%ae%a4%e5%80%bc%e6%80%8e%e4%b9%88%e5%8a%9e","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6885\/","title":{"rendered":"JPA\u4fdd\u5b58\u5b9e\u4f53\u62a5\u9519Column cannot be null\uff0c\u5373\u4f7f\u6570\u636e\u5e93\u6709\u9ed8\u8ba4\u503c\u600e\u4e48\u529e\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173001133614740.jpg\" class=\"aligncenter\" title=\"JPA\u4fdd\u5b58\u5b9e\u4f53\u62a5\u9519Column cannot be null\uff0c\u5373\u4f7f\u6570\u636e\u5e93\u6709\u9ed8\u8ba4\u503c\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" alt=\"JPA\u4fdd\u5b58\u5b9e\u4f53\u62a5\u9519Column cannot be null\uff0c\u5373\u4f7f\u6570\u636e\u5e93\u6709\u9ed8\u8ba4\u503c\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>jpa \u4fdd\u5b58\u5b9e\u4f53\u62a5\u9519 column cannot be null\uff0c\u5373\u4f7f\u6570\u636e\u5e93\u6709\u9ed8\u8ba4\u503c<\/strong><\/p>\n<p>\u5f53\u4fdd\u5b58\u4e00\u4e2a\u5b9e\u4f53\u65f6\uff0c\u5c3d\u7ba1\u6570\u636e\u5e93\u7684\u5b57\u6bb5\u5df2\u7ecf\u8bbe\u7f6e\u4e86\u9ed8\u8ba4\u503c\uff0c\u4f46\u4ecd\u7136\u53ef\u80fd\u4f1a\u9047\u5230 <strong>column cannot be null<\/strong> \u7684\u62a5\u9519\u3002<\/p>\n<p><strong>\u539f\u56e0\uff1a<\/strong><\/p>\n<p>jpa \u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4f1a\u5bf9\u5b9e\u4f53\u5b57\u6bb5\u8fdb\u884c\u5168\u91cf\u64cd\u4f5c\uff0c\u5373\u65e0\u8bba\u5b57\u6bb5\u662f\u5426\u6709\u503c\uff0c\u90fd\u4f1a\u5728 sql \u8bed\u53e5\u4e2d\u5305\u542b\u8be5\u5b57\u6bb5\u3002\u56e0\u6b64\uff0c\u5373\u4f7f\u6570\u636e\u5e93\u5b57\u6bb5\u6709\u9ed8\u8ba4\u503c\uff0cjpa \u751f\u6210\u7684 sql \u8bed\u53e5\u4ecd\u4f1a\u5411\u8be5\u5b57\u6bb5\u63d2\u5165\u7a7a\u503c\uff08null\uff09\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u7ed9\u5b9e\u4f53\u5b57\u6bb5\u6dfb\u52a0 <strong>@dynamicinsert<\/strong> \u6ce8\u89e3\u3002\u8be5\u6ce8\u89e3\u4f1a\u6307\u793a jpa \u5728\u5411\u6570\u636e\u5e93\u63d2\u5165\u6570\u636e\u65f6\uff0c\u53ea\u64cd\u4f5c\u6709\u975e\u7a7a\u503c\u7684\u5b57\u6bb5\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>public class XXX { \n    @DynamicInsert\n    @Column(name = \"`aaa`\")\n    private String aaa;\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4f7f\u7528 <strong>@dynamicinsert<\/strong> \u6ce8\u89e3\u540e\uff0cjpa \u53ea\u4f1a\u5728 aaa \u5b57\u6bb5\u6709\u503c\u65f6\u5411\u5176\u63d2\u5165\u6570\u636e\uff0c\u4ece\u800c\u907f\u514d\u4e86 column cannot be null \u7684\u9519\u8bef\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJPA\u4fdd\u5b58\u5b9e\u4f53\u62a5\u9519Column cannot be null\uff0c\u5373\u4f7f\u6570\u636e\u5e93\u6709\u9ed8\u8ba4\u503c\u600e\u4e48\u529e\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 \u4fdd\u5b58\u5b9e\u4f53\u62a5\u9519 column cannot be null\uff0c\u5373\u4f7f\u6570\u636e\u5e93\u6709\u9ed8\u8ba4\u503c \u5f53\u4fdd\u5b58\u4e00\u4e2a\u5b9e\u4f53\u65f6\uff0c\u5c3d\u7ba1\u6570\u636e\u5e93\u7684\u5b57\u6bb5\u5df2\u7ecf\u8bbe\u7f6e\u4e86\u9ed8\u8ba4\u503c\uff0c\u4f46\u4ecd\u7136\u53ef\u80fd\u4f1a\u9047\u5230 column cannot be null \u7684\u62a5\u9519\u3002 \u539f\u56e0\uff1a jpa \u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4f1a\u5bf9\u5b9e\u4f53\u5b57\u6bb5\u8fdb\u884c\u5168\u91cf\u64cd\u4f5c\uff0c\u5373\u65e0\u8bba\u5b57\u6bb5\u662f\u5426\u6709\u503c\uff0c\u90fd\u4f1a\u5728 sql \u8bed\u53e5\u4e2d\u5305\u542b\u8be5\u5b57\u6bb5\u3002\u56e0\u6b64\uff0c\u5373\u4f7f\u6570\u636e\u5e93\u5b57\u6bb5\u6709\u9ed8\u8ba4\u503c\uff0cjpa \u751f\u6210\u7684 sql \u8bed\u53e5\u4ecd\u4f1a\u5411\u8be5\u5b57\u6bb5\u63d2\u5165\u7a7a\u503c\uff08null\uff09\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a \u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u7ed9\u5b9e\u4f53\u5b57\u6bb5\u6dfb\u52a0 @dynamicinsert \u6ce8\u89e3\u3002\u8be5\u6ce8\u89e3\u4f1a\u6307\u793a jpa \u5728\u5411\u6570\u636e\u5e93\u63d2\u5165\u6570\u636e\u65f6\uff0c\u53ea\u64cd\u4f5c\u6709\u975e\u7a7a\u503c\u7684\u5b57\u6bb5\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a public class XXX { @DynamicInsert @Column(name = &#8220;`aaa`&#8221;) private String aaa; } \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 @dynamicinsert \u6ce8\u89e3\u540e\uff0cjpa \u53ea\u4f1a\u5728 aaa \u5b57\u6bb5\u6709\u503c\u65f6\u5411\u5176\u63d2\u5165\u6570\u636e\uff0c\u4ece\u800c\u907f\u514d\u4e86 column cannot be null \u7684\u9519\u8bef\u3002 \u4ee5\u4e0a\u5c31\u662fJPA\u4fdd\u5b58\u5b9e\u4f53\u62a5\u9519Column cannot be null\uff0c\u5373\u4f7f\u6570\u636e\u5e93\u6709\u9ed8\u8ba4\u503c\u600e\u4e48\u529e\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-6885","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6885","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=6885"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6885\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6885"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6885"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6885"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}