You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by "Hofmann, Tobias" <to...@sap.com> on 2016/04/08 16:05:38 UTC

Olingo v2 JPA creating child entity

Hi,

I am exposing JPA entities (parent, child, annotated via @ManyToOne, @OneToMany) using olingo v2.0.6 and while everything works just fine, I am wondering how to create a child entity. If none of the entities exists (sensor, measurement), I can POST this:

/iot/olingo.svc/Sensors
{"Device": "sensor1",
                "MeasurementDetails" : [ {"Unit": "Celsius", "Value": "11.11"} ]
}

And both get created and linked.  If I already have the parent sensor entity, and want to add a new measurement, it works when posting:

/iot/olingo.svc/Measurements
{ "Unit":"Celsius",  "Value": "9",
  "SensorDetails":   {
      "__metadata":       {
         "uri":http://localhost:7080/iot/olingo.svc/Sensors(1L)
}}}

I thought that I can also create a mesasurement linked to an existing sensor by posting this:

/iot/olingo.svc/Sensors(1L)/MeasurementDetails
{"Unit": "Celsius", "Value": "99"}

Using the last example, the measurement entity gets created, but is not linked to sensor(1). Is this how it should work?

Tobias Hofmann [SAP Mentor -] <http://sapmentors.sap.com/>
Senior Consultant I Consulting
SAP Brasil I Av. Rio Branco 138 - 8o andar I 20048-002 Rio de Janeiro I Brazil
M: 55 11 9-8673-7936 / E: tobias.hofmann@sap.com<ma...@sap.com>

Join me online: SAP Mentors<http://sapmentors.sap.com/> | SCN<http://scn.sap.com/people/tobias.hofmann> | Twitter<http://twitter.com/tobiashofmann> I Linkedln<http://br.linkedin.com/pub/tobias-hofmann/5/b08/768>