Skip to content
Advertisement

JPA SpringBoot – Unable to Save New Entity to Database

I am attempting to add (save) a “User” to my SQL database through my Spring application (The @GetMapping requests currently work). I recently added the two annotations @CreationTimeStamp and @UpdateTimeStamp in my entity class…the version without those two annotations would produce the same errors as shown. I am testing the API with Postman-here is my Users entity class:

JavaScript

my UsersDTO class

JavaScript

My UsersServiceImpl

JavaScript

My UsersAPI class

JavaScript

Whenever I try to add a User through Postman I am given this error (I included the hibernate lines):

JavaScript

This is the JSON body I am inputting into Postman (Body -> raw and JSON selected as options) :

JavaScript

and Postman gives this error:

JavaScript

I am able to manually add a user in MySQL Shell with:

JavaScript

I do have an @EmbdeddId in my Followers Entity but I don’t think that would affect me adding a User.

JavaScript

and the @Embeddable class

JavaScript

Here is my UML diagram for the database: https://drive.google.com/file/d/1xljVZVRvEMGkKVULBi-Suqn1RFO_b7b7/view?usp=sharing

Here is the SQL script:

JavaScript

I am not sure what’s causing my problem…please help! Thank you

Advertisement

Answer

first all keep one code style сamelCase or snake_case. You send “first_last_name”, but expects “firstLastName”. Not necessary sending fields login_at, created_at you have already put the appropriate annotations .

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement