I have two entities with a relation one to many
public class Order {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
pri
Just add parameter exported=false to @RepositoryRestResrouce annotation in your Item repo. Then you can create Order with Item in one request:
{
"userName": "Marco",
"company": "MP",
"items": [
{
"name": "CD",
"quantity": "10"
},
{
"name": "DVD",
"quantity": "5"
}
]
}
I recommend you to add cascade = CascadeType.ALL, orphanRemoval = true to items in Order to make items fully managed by Order.
Additional info.
If you want to work with Order and Item independently you can leave all as is but first create you items:
POST http://localhost:8080/items
{
{
"name": "CD",
"quantity": "10"
},
{
"name": "DVD",
"quantity": "5"
}
}
then create Order that contains them:
POST http://localhost:8080/orders
{
{
"userName": "Marco",
"company": "MP",
"items": [
"http://localhost:8080/items/1",
"http://localhost:8080/items/2"
]
}
}
You use @JoinColumn annotation with items - so I think you must implement synchronization between Order and Items in that case...
And please don't post JSON in one line ))