{"id":6887,"date":"2024-11-14T11:44:44","date_gmt":"2024-11-14T03:44:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6887\/"},"modified":"2024-11-14T11:44:44","modified_gmt":"2024-11-14T03:44:44","slug":"jpa-%e4%bf%9d%e5%ad%98%e6%93%8d%e4%bd%9c%e4%b8%ba%e4%bd%95%e5%9c%a8%e5%ad%97%e6%ae%b5%e6%9c%89%e9%bb%98%e8%ae%a4%e5%80%bc%e6%97%b6%e4%bb%8d%e6%8a%9b%e5%87%bacolumn-cannot-be-null","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6887\/","title":{"rendered":"JPA \u4fdd\u5b58\u64cd\u4f5c\u4e3a\u4f55\u5728\u5b57\u6bb5\u6709\u9ed8\u8ba4\u503c\u65f6\u4ecd\u629b\u51fa\u201cColumn cannot be null\u201d\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173001528335469.jpg\" class=\"aligncenter\" title=\"JPA \u4fdd\u5b58\u64cd\u4f5c\u4e3a\u4f55\u5728\u5b57\u6bb5\u6709\u9ed8\u8ba4\u503c\u65f6\u4ecd\u629b\u51fa\u201cColumn cannot be null\u201d\uff1f\u63d2\u56fe\" alt=\"JPA \u4fdd\u5b58\u64cd\u4f5c\u4e3a\u4f55\u5728\u5b57\u6bb5\u6709\u9ed8\u8ba4\u503c\u65f6\u4ecd\u629b\u51fa\u201cColumn cannot be null\u201d\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>jpa\u4fdd\u5b58\u64cd\u4f5c\u4e3a\u4f55\u5728\u5b57\u6bb5\u6709\u9ed8\u8ba4\u503c\u65f6\u4ecd\u629b\u51fa\u201ccolumn cannot be null\u201d\uff1f<\/strong><\/p>\n<p>\u5728 spring data jpa \u9879\u76ee\u4e2d\uff0c\u9047\u5230\u4ee5\u4e0b\u9519\u8bef\u4fe1\u606f\uff1a<\/p>\n<pre>could not execute statement; sql [n\/a]; constraint [null]; nested exception is org.hibernate.exception.constraintviolationexception: could not execute statement<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<pre>column 'aaa' cannot be null<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6570\u636e\u5e93\u5b57\u6bb5 aaa \u7684\u5b9a\u4e49\uff1a<\/p>\n<pre>`aaa` varchar(255) not null default ''<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5b9e\u4f53\u7c7b\u5b57\u6bb5\uff1a<\/p>\n<pre>private string aaa;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e3a\u4ec0\u4e48\u5728\u6570\u636e\u5e93\u5df2\u8bbe\u7f6e\u9ed8\u8ba4\u503c\u7684\u60c5\u51b5\u4e0b\uff0c\u4fdd\u5b58\u64cd\u4f5c\u4ecd\u4f1a\u629b\u51fa column cannot be null \u5f02\u5e38\uff1f<\/p>\n<p><strong>\u539f\u56e0\uff1a<\/strong><\/p>\n<p>jpa \u9ed8\u8ba4\u4f7f\u7528\u5168\u91cf\u66f4\u65b0\u5b57\u6bb5\uff0c\u5373\u4f7f\u5b57\u6bb5\u5df2\u6709\u9ed8\u8ba4\u503c\uff0c\u4e5f\u4f1a\u5c1d\u8bd5\u5411\u5b57\u6bb5\u63d2\u5165 null \u503c\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u82e5\u60f3\u5728\u5b57\u6bb5\u4e3a\u7a7a\u65f6\u91c7\u7528\u6570\u636e\u5e93\u9ed8\u8ba4\u503c\uff0c\u5e94\u4e3a\u5b57\u6bb5\u6dfb\u52a0 @dynamicinsert \u6ce8\u89e3\u3002\u8be5\u6ce8\u89e3\u6307\u793a jpa \u4ec5\u5728\u5b57\u6bb5\u4e0d\u4e3a\u7a7a\u65f6\u624d\u63d2\u5165\u8be5\u5b57\u6bb5\u3002<\/p>\n<pre>@DynamicInsert\npublic class XXX {\n\n    @Column(name = \"`aaa`\")\n    private String aaa;\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6dfb\u52a0 @dynamicinsert \u6ce8\u89e3\u540e\uff0cjpa \u751f\u6210\u7684 sql \u8bed\u53e5\u5c06\u4ec5\u5728 aaa \u5b57\u6bb5\u4e0d\u4e3a\u7a7a\u65f6\u624d\u63d2\u5165\u8be5\u5b57\u6bb5\uff0c\u4ece\u800c\u907f\u514d\u4e86 column cannot be null \u5f02\u5e38\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJPA \u4fdd\u5b58\u64cd\u4f5c\u4e3a\u4f55\u5728\u5b57\u6bb5\u6709\u9ed8\u8ba4\u503c\u65f6\u4ecd\u629b\u51fa\u201cColumn cannot be null\u201d\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\u64cd\u4f5c\u4e3a\u4f55\u5728\u5b57\u6bb5\u6709\u9ed8\u8ba4\u503c\u65f6\u4ecd\u629b\u51fa\u201ccolumn cannot be null\u201d\uff1f \u5728 spring data jpa \u9879\u76ee\u4e2d\uff0c\u9047\u5230\u4ee5\u4e0b\u9519\u8bef\u4fe1\u606f\uff1a could not execute statement; sql [n\/a]; constraint [null]; nested exception is org.hibernate.exception.constraintviolationexception: could not execute statement \u767b\u5f55\u540e\u590d\u5236 column &#8216;aaa&#8217; cannot be null \u767b\u5f55\u540e\u590d\u5236 \u6570\u636e\u5e93\u5b57\u6bb5 aaa \u7684\u5b9a\u4e49\uff1a `aaa` varchar(255) not null default &#8221; \u767b\u5f55\u540e\u590d\u5236 \u5b9e\u4f53\u7c7b\u5b57\u6bb5\uff1a private string aaa; \u767b\u5f55\u540e\u590d\u5236 \u4e3a\u4ec0\u4e48\u5728\u6570\u636e\u5e93\u5df2\u8bbe\u7f6e\u9ed8\u8ba4\u503c\u7684\u60c5\u51b5\u4e0b\uff0c\u4fdd\u5b58\u64cd\u4f5c\u4ecd\u4f1a\u629b\u51fa column cannot be null \u5f02\u5e38\uff1f \u539f\u56e0\uff1a jpa [&hellip;]<\/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-6887","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6887","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=6887"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6887\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6887"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6887"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}