Skip to content
Advertisement

Column ‘foreign_key_id’ cannot be null

I have a rest api exposed via @RepositoryRestResource from spring-data-rest-api. When I try to give the json payload from Postman to create a User linked to an Organization, it complains that Column 'organizationId' cannot be null, when I clearly provided it in the json.

JavaScript

Each user belongs to an organization, so it’s a many to one relationship. I want Java to map the Organization that the User belongs to into the User as an Organization object.

User.java:

JavaScript

Organization.java:

JavaScript

Any help is greatly appreciated.

Advertisement

Answer

This is the appoach I ended up going with. Still would like to know why the @ManyToOne annotation isn’t saving the organizationId as a foreign key in the User table by itself.

User.java:

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