spring - 404 on setting an association resource -
my first experiment spring data rest fails. i've taken "getting started" , modified bit create 2 entities have many-to-one relationships. entities book
, shelve
, many books can share shelve.
the shelve
entity looks this:
package hello; import javax.persistence.entity; import javax.persistence.generatedvalue; import javax.persistence.generationtype; import javax.persistence.id; @entity public class shelve { @id @generatedvalue(strategy = generationtype.auto) private long id; private int length; public int getlength() { return length; } public void setlength(int length) { this.length = length; } }
the book
refers it:
package hello; import javax.persistence.entity; import javax.persistence.generatedvalue; import javax.persistence.generationtype; import javax.persistence.id; import javax.persistence.manytoone; @entity public class book { @id @generatedvalue(strategy = generationtype.auto) private long id; private string title; @manytoone private shelve shelve; public string gettitle() { return title; } public void settitle(string title) { this.title = title; } public shelve getshelve() { return shelve; } public void setshelve(shelve shelve) { this.shelve = shelve; } }
the full project available here in github.
now can add shelve:
curl -i -x post -h "content-type:application/json" -d "{ \"length\" : \"30\" }" http://localhost:8080/shelves http/1.1 201 location: http://localhost:8080/shelves/1 content-type: application/hal+json;charset=utf-8 transfer-encoding: chunked date: thu, 17 nov 2016 16:05:02 gmt { "length" : 30, "_links" : { "self" : { "href" : "http://localhost:8080/shelves/1" }, "shelve" : { "href" : "http://localhost:8080/shelves/1" } } }
then book:
curl -i -x post -h "content-type:application/json" -d "{ \"title\" : \"the battle of life\" }" http://localhost:8080/books http/1.1 201 location: http://localhost:8080/books/1 content-type: application/hal+json;charset=utf-8 transfer-encoding: chunked date: thu, 17 nov 2016 16:05:02 gmt { "title" : "the battle of life", "_links" : { "self" : { "href" : "http://localhost:8080/books/1" }, "book" : { "href" : "http://localhost:8080/books/1" }, "shelve" : { "href" : "http://localhost:8080/books/1/shelve" } } }
then try put book on shelve, fails:
curl -i -x put -h "contenttype: text/uri-list" -d "http://localhost:8080/shelves/1" http://localhost:8080/books/1/shelve http/1.1 404 content-type: application/json;charset=utf-8 transfer-encoding: chunked date: thu, 17 nov 2016 16:05:02 gmt {"timestamp":1479398702523,"status":404,"error":"not found","message":"no message available","path":"/books/1/shelve"}
any idea what's going wrong here?
as pointed out oliver gierke on the related jira ticket, issue in curl
request. should have hypen in content-type
:
curl -i -x put -h "content-type: text/uri-list" -d "http://localhost:8080/shelves/1" http://localhost:8080/books/1/shelve http/1.1 204 date: sat, 19 nov 2016 16:50:24 gmt
so works expected, provided use right way :)
@oliver: lot!
Comments
Post a Comment