SAP / olingo-jpa-processor-v4

The JPA Processor fills the gap between Olingo V4 and the database, by providing a mapping between JPA metadata and OData metadata, generating queries and supporting the entity manipulations.
Apache License 2.0
128 stars 79 forks source link

Unable to sort on fields that are part of composite key #23

Closed BlueCatSpy closed 11 months ago

BlueCatSpy commented 6 years ago

While it is possible to filter on a field that is part of a composite key, trying to order by it will raise an exception with a message that looks like the following: Property for 'foo' not found at 'bar'.

A filter expression would filter correctly the foo field to 'bar.id.foo' while the order by is looking for 'bar.foo' which doesn't exist.

wog48 commented 6 years ago

Hello, In my opinion the behavior of order by is the correct one and what you describe for filter is wrong. Let me explain why:

I assume that your jpa entity look like follows:

@Entity
public class Bar {

  @EmbeddedId
  private BarPK id;
  ...
}
@Embeddable
public class BarPK 

  @Column(name = "\"...\"", length = ...)
  private String foo;
  ...
}

For my understanding the OData specification does not allow a complex type. E.g. Part 3, 8.2 Element edm:Key states:

The properties that compose the key MUST be non-nullable and typed with an enumeration type, one of the following primitive types, or a type definition based on one of these primitive types: ...

That's why IntermediateEntityType.getKey() "flats" embedded ids and the metadata document should look like:

<EntityType Name="Bar">
    <Key>
        <PropertyRef Name="Foo"/>
        ...
    </Key>
    ...
</EntityType>

I tried to reproduce the behavior you describe, but I was not able to. Please give my more details, so I can find out whats going wrong.

wog48 commented 11 months ago

Due to clean-up action. All issues created before 2022 get closed.