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
123 stars 76 forks source link

Embeddable ComplexType cannot be queried #109

Closed DimitarPetrov closed 2 years ago

DimitarPetrov commented 3 years ago

Hello,

I have encountered a problem when trying to query fields of a @Embeddable ComplexType. The setup is as follows:

I have an @Embeddable class like this:

@Embeddable
public class Link {
    @Column(name = "title", length = Integer.MAX_VALUE)
    private String title;

    @Column(name = "description", length = Integer.MAX_VALUE)
    private String description;

    @Column(name = "url", length = Integer.MAX_VALUE)
    private String url;

    @Column(name = "extensions", length = Integer.MAX_VALUE)
    private String extensions;
}

And I use it in the @Entity class like this:

    @ElementCollection
    @CollectionTable(name = "links", joinColumns = @JoinColumn(name = "package_id"))
    private List<Link> links;

When I get OData $metadata everything looks perfectly fine:

"package": {
     ...
     "links": {
        "$Type": "com.sap.cloud.cmp.ord.service.Link",
        "$Collection": true
      },
     ...
}
   "Link": {
      "$Kind": "ComplexType",
      "extensions": {
        "$Type": "Edm.String",
        "$MaxLength": 2147483647
      },
      "description": {
        "$Type": "Edm.String",
        "$MaxLength": 2147483647
      },
      "title": {
        "$Type": "Edm.String",
        "$MaxLength": 2147483647
      },
      "url": {
        "$Type": "Edm.String",
        "$MaxLength": 2147483647
      }
    },

However when I execute the following query:

/packages?$filter=links/any(d:startswith(d/title,%27More%27))&$format=JSON

I got:

{
  "error": {
    "code": null,
    "message": "OData Library: An exception without message text was thrown."
  }
}
DimitarPetrov commented 2 years ago

In order for query by Complex Type to work, an Entity for each Complex type (Embeddable in JPA) should be created as well.