When trying to use JPA to insert data into a MySQL Database, i am thrown the exception: Column 'billing_address' cannot be null


Like the title says, when trying to use JPA to use an @PostMapping annotation to create a ‘customer’ in my test database, i get thrown the excpetion:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement] with root cause

java.sql.SQLIntegrityConstraintViolationException: Column 'billing_address' cannot be null

I tried to pass in a JSON body using postman to create a few entries in the database, but would keep receiving this error no matter what I seemed to change.

This is my class implementation of my repository


This is my Repository interface.


And finally this is my customer entity


If anyone could point me in the right direction on how to fix this error, i would greatly appreciate it. This is the first API I’ve tried to develop and i have been stuck on this issue for far too long. Linked below is my github if anyone wants to dig into the code for themselves.




What about your database? Are you using an existent one or is it generated/handled by hibernate with your JPA settings?

You should check the related DDL table for that column, because it looks like the database table is "different" from your entity mapping.

Answered By – sigur

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published