Spring Rest: Cannot insert rows that have @ManyToOne column

和自甴很熟 提交于 2019-11-29 17:26:57

There is no way for your BikeRepository to know which row is represented by Person : { firstName : "Frodo", lastName : "Baggins" }. You have to tell your BikeRepository how to or where to query for that.

Try

curl -i -X POST -H "Content-Type:application/json" -d "{ \"name\" : \Frodos Bike\", \"person\" : "http://localhost:8080/people/1" }" http://localhost:8080/bikes

That like will query http://localhost:8080/people/1 for the Person Entity.

It will also work with parameters based query, just replace the {id} query with http://localhost:8080/people?name='Frodo'

Hope that helps!

Try with curl -i -X POST -H "Content-Type:application/json" -d "{ \"name\" : \"Frodos Bike\", \"person\" : \"/people/1\" }" http://localhost:8080/bikes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!