本ページはプロモーションが含まれています。

スポンサーリンク

java.sql.SQLIntegrityConstraintViolationException: Column 'xxxx' cannot be null SpringBootでDBアクセス時のエラー

2021-02-11 23:18:06.941 ERROR 11672 --- [nio-8081-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: [DOMA2009] SQLの実行に失敗しました。
SQLファイルパス=[null]。
ログ用SQL=[]。
原因は次のものです。java.sql.SQLIntegrityConstraintViolationException: Column 'author_name' cannot be null。
根本原因は次のものです。java.sql.SQLIntegrityConstraintViolationException: Column 'author_name' cannot be null; SQL [insert into m_book (book_name, book_name_kana, author_name, author_name_kana, isbn, price, cover_image, cover_back_image) values (?, ?, ?, ?, ?, ?, ?, ?)]; Column 'author_name' cannot be null; nested exception is java.sql.SQLIntegrityConstraintViolationException: Column 'author_name' cannot be null] with root cause

java.sql.SQLIntegrityConstraintViolationException: Column 'author_name' cannot be null
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:117) ~[mysql-connector-java-8.0.22.jar:8.0.22]

>>SQLIntegrityConstraintViolationExceptionの公式APIはこちら

発生理由:
整合性制約 (外部キー、主キー、または一意キー) の違反が発生した。
この場合は「Column 'xxx' cannot be null」とある通り、INSERTまたはUPDATE対象のテーブルのxxxカラムにnullを設定しようとしたため。

解決策:
xxxカラムにセットする値は必ず必須チェックをすること。

スポンサーリンク

投稿日:

Copyright© 【Spring Hack】 , 2024 All Rights Reserved Powered by AFFINGER5.