我在使用odata4j库检索相关实体时遇到了问题。我的问题如下:
A与B有一对多的关系。A有一个B类型项的列表,"bs“。我创建了实体A,并使用
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();然后,我使用以下方法检索实体B,其中转换将检索对象的属性分配给A类型的对象:
A b = convert(consumer.getEntity("A", id).expand("bs").execute());在转换过程中,我试图让相关实体使用:
OEntity bsOEntity = a.getLink("bs", OLink.class).getRelatedEntity();上面的结果是检索了一个链接,但是"getRelatedEntity“返回null
我是否使用了链接和相关实体错误?如果是这样,我将如何在Odata4j中检索相关实体?网上的例子不多。
你的帮助将不胜感激。
谢谢
编辑:我还尝试使用以下方法检索相关实体:
ORelatedEntitiesLink link = (ORelatedEntitiesLink) a.getLinks().get(0);
OEntity retrievedEntity = consumer.getEntities(link).top(1).execute().first();我尝试使用以下方法创建链接,这似乎也是一样的,但是通过额外的调用获取实体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();发布于 2013-12-25 01:28:40
你试过getRelatedEntities()而不是getRelatedEntity()吗?根据你的解释,我知道A有一个B的集合,所以试试
List<OEntity> bsOEntities = a.getLink("bs", OLink.class).getRelatedEntities();
对我来说很管用。
https://stackoverflow.com/questions/19113948
复制相似问题