【问题标题】:How to read a collection of entities with complex properties in olingo?如何在 olingo 中读取具有复杂属性的实体集合?
【发布时间】:2020-02-19 19:34:53
【问题描述】:

我大致关注这个来自 apache olingo 页面的Tutorial。我想读取具有复杂属性的实体集合。

设置提供程序,访问http://localhost:8080/api/odata/$metadata时得到以下输出:

<?xml version="1.0" encoding="UTF-8"?>
<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
    <edmx:DataServices>
        <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="My.Namespace">
            <EntityType Name="MyEntity">
                <Key>
                    <PropertyRef Name="id"/>
                </Key>
                <Property Name="id" Type="Edm.String"></Property>
                <Property Name="name" Type="Edm.String"></Property>
                <Property Name="description" Type="Edm.String"></Property>
                <Property Name="complexProp" Type="My.Namespace.MyComplexType"></Property>
            </EntityType>
            <ComplexType Name="MyComplexType">
                <Property Name="id" Type="Edm.String"></Property>
                <Property Name="name" Type="Edm.String"></Property>
            </ComplexType>
            <EntityContainer Name="Container">
                <EntitySet Name="MyEntities" EntityType="My.Namespace.MyEntity"></EntitySet>
            </EntityContainer>
        </Schema>
    </edmx:DataServices>
</edmx:Edmx>

这对我来说似乎没问题(是吗?)。但是我尝试读取访问http://localhost:8080/api/odata/MyEntities 的实体集合,我收到了返回消息

Cannot find type with name: My.Namespace.MyComplexType

当在序列化程序上调用 entityCollection 时,单步执行代码会显示处理器的 readEntityCollection 方法中抛出的期望。

我必须错过重要的一点,因为在我看来My.Namespace.MyComplexType 的定义很明确。

【问题讨论】:

  • 如果您认为$metadata 输出有效,请发表评论。

标签: java odata olingo


【解决方案1】:

虽然在处理器中抛出了异常,但该错误与序列化无关。

找不到复杂类型MyComplexType,因为在EdmProvider 中只覆盖了getEntityType(final FullQualifiedName entityTypeName),而不是getComplexType(final FullQualifiedName complexTypeName)olingo 似乎通过调用这些方法来搜索类型。

覆盖此方法后,所有数据均已正确显示。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多