this is my region class :
@Entity(name = "REGION")
public class Region {
private Long id;
private String region;
@OneToMany(targetEntity = Compagnie.class, mappedBy = "region", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Set<Compagnie> compagnie;
this is my Compagnie class :
@Entity(name = "COMPAGNIE")
public class Compagnie {
private Long id;
private String compagnie;
@ManyToOne
@JoinColumn(name = "REGION_ID")
private Region region;
this is my edit method from controller class :
@RequestMapping(value = "/compagnie/{id}", method = RequestMethod.GET)
public ResponseEntity<?> getCompagnie(@PathVariable("id") long id) {
logger.info("Fetching Compagnie with id {}", id);
Compagnie compagnie = compagnieRepository.findOne(id);
if (compagnie == null) {
logger.error("Compagnie with id {} not found.", id);
return new ResponseEntity(new CustomErrorType("Unable to update. Compagnie with id " + id + " not found."),
HttpStatus.NOT_FOUND);
}
return new ResponseEntity<Compagnie>(compagnie, HttpStatus.OK);
}
the json that i use for test is :
{ "compagnie": "test compagnie 1", "region": { "id": 1, "region": "region 1" } }
the compagnie change but the region wont and i cant be able to read the region attributes from the @requestBody .
i really need your help . thanks .