Skip to content
Advertisement

Spring Boot CrudRepository not saving entities to my database

I’ve been at this for a few hours now and can’t seem to find the issue.

For a bit of context, here is my database schema :

Database schema

Here is my Student class :

JavaScript

And here is my Task class :

JavaScript

My H2 Database structure therefore looks like this :

H2 Database structure

I am trying to add a task to a student through a rest controller (the rest controller works fine) :

JavaScript

Here is my Exercises class :

JavaScript

Here are the logs from the code :

JavaScript

As you can see, the Task does seem to be added to the database – except it doesn’t 🙁

Database data

☝️ There should be a “4, 3” (4 being the task id and 3 the student “number”).

Oh, and while I’m at it, here is my StudentDB class :

JavaScript

I’m still quite new to Spring so it’s probably just me missing something :/
Thanks in advance for your help !

Advertisement

Answer

As @MauricePerry commented, adding the student to the task instead of adding the task to the student worked 🧐

For anyone encountering the same issue, I now have the following code :

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