Skip to content
Advertisement

Getting null value reference in One to Many mapping in Spingboot

I am trying to implement ONE-to-MANY mapping among two entities. In here designations have a location and a location have many designations. Once I added the designation it mapped fine, but it update the location table with null except id.

Here I’m using the Microsoft SQL server. Application Properties

JavaScript

DesignationMaster

JavaScript

LocationMaster

JavaScript

Service class of Designations

JavaScript

Controller class of Designation

JavaScript

I pass data to backend as this

JavaScript

And it updated the database, but it change others values to null in location table, and get request like this

JavaScript

As in the database -Location table enter image description here

-Designation table enter image description here

I went through many methods but nothing works for me. Is there anyone who can make my day better?

Advertisement

Answer

Its work after change the createDesignation(DesignationMaster desData) in service class as follows

JavaScript

where I fetch the location data from its repository and set that object to the destination object. So that its work fine.

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