1
Good afternoon, everyone,
I’m having a doubt, I try to persist a JSON through the API:
{
...
"Analise": [{
"nProcAnalitic": "SR-000446/2015",
...
}]
...
}
And the service answers me 200:
...
"Analise": [
{
"id": null,
"lotEntity": null,
"nProcAnalitic": "SR-000446/2015"
...
However without creating the listing object, only the parent object.
Mapping:
@Jsonproperty("Analyze") @Onetomany(mappedBy = "lotEntity") private list analysis;
...
@Manytoone @Joincolumn(name = "id_lot") Private Lotentity lotEntity;
Actually, Cascade.ALL was missing, but the parent reference object within the listing did not save the id, leaving null... ... "Scan": [ { "id": 3, "lotEntity": null,
– user39564
You must set the parent entity in the daughter entity manually. I advise you to use the @postPersist annotation in a method in the parent class, so the JPA insert the parent entity, and before inserting the children, it will invoke this method and you can set the parent object (this) in the child object (analyze).
– Fábio Zoz
Oops, it worked: @Postpersist public void setObject() { this.analysis.foreach(a -> a.setLotEntity(this)); } Thanks
– user39564