[
https://issues.apache.org/jira/browse/OLINGO-462?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14185170#comment-14185170
]
Michael Bolz commented on OLINGO-462:
-------------------------------------
Hi [~zelotypus],
in the OData specification for an {{AssociationSet end}} is defined:
{quote}
Chapter: 2.1.19 AssociationSet End
* The <End> element's Role MUST map to a Role declared on one of the <Ends> of
the <Assocation> referenced by the <End> element's declaring <AssociationSet>.
* Each <End>declared by an <AssociationSet> MUST refer to a different Role.
{quote}
Based on that we implemented it in the library.
If you would change the role name of the association “Employee_colleagues” with
multiplicity “*” to e.g. {{Role=“Colleagues”}} all should work as expected.
Sure you could argument that the “Role” is optional, but if given it MUST refer
to different “Role” (values).
BTW I think using different names for different roles is also a best practice
for defining the EDM.
Kind regards,
Michael
> Multiplicity of navigation property is determined incorrectly
> -------------------------------------------------------------
>
> Key: OLINGO-462
> URL: https://issues.apache.org/jira/browse/OLINGO-462
> Project: Olingo
> Issue Type: Bug
> Components: odata2-core
> Affects Versions: V2 2.0.0
> Reporter: Vitali Yarmolik
>
> There is the following metadata of an OData service:
> {code:xml}
> <?xml version='1.0' encoding='UTF-8'?>
> <edmx:Edmx Version="1.0"
> xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
> <edmx:DataServices m:DataServiceVersion="1.0"
> xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
> <Schema Namespace="TestNamespace"
> xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
> <EntityType Name="Data">
> <Key>
> <PropertyRef Name="Key" />
> </Key>
> <Property Name="Key" Type="Edm.String" Nullable="false" />
> <NavigationProperty Name="Employee"
> Relationship="TestNamespace.Data_Employee" FromRole="Data"
> ToRole="Employee" />
> </EntityType>
> <EntityType Name="Employee">
> <Key>
> <PropertyRef Name="Key" />
> </Key>
> <Property Name="Key" Type="Edm.String" Nullable="false" />
> <Property Name="firstName" Type="Edm.String" Nullable="true" />
> <Property Name="lastName" Type="Edm.String" Nullable="true" />
> <NavigationProperty Name="colleagues"
> Relationship="TestNamespace.Employee_colleagues" FromRole="Employee"
> ToRole="Employee" />
> </EntityType>
> <Association Name="Data_Employee">
> <End Type="TestNamespace.Data" Multiplicity="1" Role="Data" />
> <End Type="TestNamespace.Employee" Multiplicity="1" Role="Employee" />
> </Association>
> <Association Name="Employee_colleagues">
> <End Type="TestNamespace.Employee" Multiplicity="1" Role="Employee" />
> <End Type="TestNamespace.Employee" Multiplicity="*" Role="Employee" />
> </Association>
> <EntityContainer Name="TestEntityContainer"
> m:IsDefaultEntityContainer="true">
> <EntitySet Name="Data" EntityType="TestNamespace.Data" />
> <EntitySet Name="Employee" EntityType="TestNamespace.Employee" />
> <AssociationSet Name="Data_Employee"
> Association="TestNamespace.Data_Employee">
> <End EntitySet="Data" Role="Data" />
> <End EntitySet="Employee" Role="Employee" />
> </AssociationSet>
> <AssociationSet Name="Employee_colleagues"
> Association="TestNamespace.Employee_colleagues">
> <End EntitySet="Employee" Role="Employee" />
> <End EntitySet="Employee" Role="Employee" />
> </AssociationSet>
> </EntityContainer>
> </Schema>
> </edmx:DataServices>
> </edmx:Edmx>
> {code}
> Having such metadata, it is not possible to expand multi-valued 'colleagues'
> navigation property of Employee entity using the following service request:
> {{.../Data?$expand=Employee/colleagues}}
> The problem is in
> {{org.apache.olingo.odata2.core.edm.provider.EdmAssociationImplProv.getEndMultiplicity(String
> role)}} method, which is called to determine whether a navigation property
> is a feed or an entry.
> {code:java}
> public EdmMultiplicity getEndMultiplicity(final String role) {
> if (association.getEnd1().getRole().equals(role)) {
> return association.getEnd1().getMultiplicity();
> }
> if (association.getEnd2().getRole().equals(role)) {
> return association.getEnd2().getMultiplicity();
> }
> return null;
> }
> {code}
> When the method is called to return multiplicity of 'colleagues' navigation
> property it returns {{EdmMultiplicity.ONE}} value because 'role' of the
> navigation property is equal to the role of End1, i.e. to the name of the
> containing entity type. As a result, it is expected that the expanded inline
> value will be an OData entry rather than a feed. It, in its turn, results in
> calling the implementation of
> {{org.apache.olingo.odata2.api.ep.callback.OnWriteEntryContent.retrieveEntryResult(WriteEntryCallbackContext)}}
> method to expand the navigation property as an entry. Because the navigation
> property is a feed and is represented as a {{java.util.List}} internally it
> cannot (and should not) be expanded as an entry.
> To fix the issue the implementation of
> {{org.apache.olingo.odata2.core.edm.provider.EdmAssociationImplProv.getEndMultiplicity(String
> role)}} method should be changed,
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)