jpenninkhof / odata-boilerplate

OpenUI5 boilerplate based on OLingo, JPA and Spring Boot
MIT License
82 stars 41 forks source link

odata-mapping.xml is missing #9

Closed mjza closed 4 years ago

mjza commented 4 years ago

I need to set the Entity Set names like "EntitySet" instead of "Entities"!

I found the following tutorial.

And in the JPAEdmExtension.java file you have a line like this:

public static final String MAPPING_MODEL = "odata-mapping.xml";

@Override
    public InputStream getJPAEdmMappingModelStream() {
        return JPAEdmExtension.class.getClassLoader().getResourceAsStream(MAPPING_MODEL);
    }

However this file is missing in the repository and I have made a file according to the tutorial that I mentioned and I have put it in the WEB-INF, but it does not change the set name as expected.

<JPAEDMMappingModel
    xmlns="http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping">
    <PersistenceUnit name="Model">
        <EDMSchemaNamespace>me.cimply</EDMSchemaNamespace>
        <JPAEntityTypes>
            <JPAEntityType name="Member">
                <EDMEntityType>Member</EDMEntityType>
                <EDMEntitySet>MemberSet</EDMEntitySet>
            </JPAEntityType>
        </JPAEntityTypes>
    </PersistenceUnit>
</JPAEDMMappingModel>

What is the problem, how can I modify the entity set name?

mjza commented 4 years ago

The place that is mentioned in the tutorial for deploying the xml file is wrong.

Deploy the JPA EDM Mapping model XML file in the root directory of your web application archive (store it in the same directory as 'WEB-INF').

What we have to do is to place the odata-mapping.xml file inside the resources folder. The file that I provided in the ticket is correct. The metadata file of building and running the server will be afterwards:

<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"
    Version="1.0">
    <edmx:DataServices
        xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
        m:DataServiceVersion="1.0">
        <Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm"
            Namespace="me.cimply">
            <EntityType Name="Member">
                <Key>
                    <PropertyRef Name="Id" />
                </Key>
                <Property xmlns:sap="http://www.sap.com/Protocols/SAPData"
                    Name="FirstName" Type="Edm.String" sap:label="First Name" />
                <Property Name="Id" Type="Edm.Int32" Nullable="false" />
                <Property xmlns:sap="http://www.sap.com/Protocols/SAPData"
                    Name="LastName" Type="Edm.String" sap:label="Last Name"
                    sap:updatable="false" sap:filterable="true" sap:creatable="false"
                    sap:sortable="true" />
            </EntityType>
            <EntityContainer Name="me.cimply"
                m:IsDefaultEntityContainer="true">
                <EntitySet Name="MemberSet" EntityType="me.cimply.Member" />
            </EntityContainer>
            <Annotations xmlns="http://docs.oasis-open.org/odata/ns/edm"
                Target="me.cimply.Member">
                <Annotation Term="com.sap.vocabularies.UI.v1.LineItem">
                    <Collection>
                        <Record Type="com.sap.vocabularies.UI.v1.DataField">
                            <PropertyValue Path="FirstName" Property="Value" />
                        </Record>
                        <Record Type="com.sap.vocabularies.UI.v1.DataField">
                            <PropertyValue Path="LastName" Property="Value" />
                        </Record>
                    </Collection>
                </Annotation>
            </Annotations>
        </Schema>
    </edmx:DataServices>
</edmx:Edmx>

It can be seen that the set name has been changed as well as the namespace!