Consider the following entity classes:
Manufacturer
: represents a car manufacturer (Ford, Volvo, ...) and has a name.Model
: represents a model (Fiesta, S80), has a name, and is manufactured by a single manufacturer.
The manufacturer field in the model is annotated as follows:
@ManyToOne
@XmlIDREF
private Manufacturer manufacturer;
I then have two REST resources defined for getting and putting both manufacturers and types. The problem is with putting types:
@PUT
@Consumes("application/xml")
public void putModel(JAXBElement<Model> model) {
modelFacade.create(model.getValue());
}
and the XML I try to put:
<model>
<name>Fiesta</name>
<manufacturer>1</manufacturer>
</model>
The manufacturer element points to 1
, a valid instance of Manufacturer
, however, when the Model is persisted, the MANUFACTURER_ID
is null
. How can I get JAXB to read the manufacturer's ID from the XML as well?
Thanks!