Spring Data Rest post to collection end-point -


i have think simple problem, after many hours of searching can find solution, , i'm relatively new spring please excuse incorrect terminology or obvious errors.

i have event object, has one-to-many relationship booking object shown below

event:

@entity public class event {     @id    @generatedvalue(strategy=generationtype.auto)    private long eventid;    private date start;    private date end;    private string title;     @onetomany(mappedby="event")    private set<booking> bookings;     protected event() {        // jpa    }    // getters , setters omitted brevity } 

booking:

@entity public class booking {       @id    @generatedvalue(strategy=generationtype.auto)    private long bookingid;    private string title;    private string contact;     @manytoone    @joincolumn(name="event_id", nullable=false)    private event event;      public divebooking() {       // jpa    }    // getters , setters omitted brevity } 

eventrepository:

public interface diveeventrepository extends jparepository<event, long> {  list<event> findbystartbetweenorendbetween(         @param("start") date startstarttime,         @param("end") date startendtime,         @param("start") date endstarttime,         @param("end") date endendtime); } 

bookingrepository

public interface bookingrepository extends jparepository<booking, long>{  } 

these expose endpoints:

/rest/events /rest/bookings

an instance of event as:

/rest/events/1

with bookings:

/rest/events/1/bookings

what i'm trying achieve, create new booking , have associated event. data model has event_id required field (as booking meaningless without event), , every fibre in being says should able post new booking object /rest/events/1/bookings , have create new booking object associated event id 1. however, whenever try , post uri, message:

failed load resource: server responded status of 405 (method not allowed)

when inspecting headers endpoint /rest/events/1/bookings can see post allowed:

access-control-allow-methods:post, get, options, delete

so i'm confused , @ loss. feels should able create booking way, , don't want go down route of having create orphaned booking associate event break data model (having make event_id null in booking), , there no way operations inside transaction (is there?). i've tried doing similar operations on other collections in model, , have post denied too, i'm guessing it's spring data rest configuration, don't know what.

thanks in advance or pointers on this.

/rest/events/1/bookings association resource. can handle uris.

if want create new booking it's logical post /rest/bookings. event field should contain uri of associated event, e.g. /rest/events/1.

btw: access-control-allow-methods not indication of methods api supports. it's relevant cross domain browser requests , it's value same every url.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -