I am having trouble retrieving related entities using the odata4j library. My problem is as follows:
A has a one to many relationship with B. A has a list, "bs", of items of type B. I created entity A and the link using
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", a.getId());
OEntity entityB = consumer.createEntity("B").properties(OProperties.string("name", "some name")).link("a", OEntityKey.create(map)).execute();
I then retrieved entity B using the following, where convert assigns the properties of the retrieved object to an object of type A:
A b = convert(consumer.getEntity("A", id).expand("bs").execute());
In the conversion I attempted to get the related entities using:
OEntity bsOEntity = a.getLink("bs", OLink.class).getRelatedEntity();
The above resulted in a link being retrieved, but "getRelatedEntity" returns null
Am I using links and related entities wrong? If so, how would I retrieve related entities in Odata4j? There are not many examples online.
Your help would be highly appreciated.
Thank you
Edit: I have also tried retrieving a related entity using:
ORelatedEntitiesLink link = (ORelatedEntitiesLink) a.getLinks().get(0);
OEntity retrievedEntity = consumer.getEntities(link).top(1).execute().first();
And I have tried to create the link using, which seems to work the same way, but with an extra call to get entity B:
OEntity bEntity = consumer.getEntity("A", FOREIGN_KEY_VALUE).execute();
OEntity medEntity = consumer.createEntity("B").properties(OProperties.string("name", "some name")).link("a", bEntity).execute();