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
122 stars 78 forks source link

Conversion of date to Edm.Date type #207

Closed mailyashgoyal closed 11 months ago

mailyashgoyal commented 1 year ago

query example: http://localhost:4003/trail_db/CustomObjectUserLicenseMetrics?$filter=MetricsDate eq 2019-09-22

When converting the last segment of the query($filter=MetricsDate eq 2019-09-22), the below function is being called

EdmPrimitiveTypeKind convertToEdmSimpleType(final Class jpaType, final Attribute currentAttribute) throws ODataJPAModelException Line number : 144 [olingo-jpa-processor-v4/JPATypeConverter.java at main · SAP/olingo-jpa-processor-v4](https://github.com/SAP/olingo-jpa-processor-v4/blob/main/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/JPATypeConverter.java#L144) Checks the currentAttribute if it is not null in order to convert the query parameter eg 2015-01-01 to Edm.Date But the calling method convertToEdmSimpleType calls the [olingo-jpa-processor-v4/JPATypeConverter.java at main · SAP/olingo-jpa-processor-v4](https://github.com/SAP/olingo-jpa-processor-v4/blob/main/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/JPATypeConverter.java#L172) With currentAttribute explicitly setting as null. So the conversion to Date will not happen at all as it never succeed in the if check. For proper conversion determineTemporalType(currentAttribute) == TemporalType.DATE should return True, which means valid determination of TemporalType with with valid object instance. The reason why it is being provided as null, the overridden method EdmPrimitiveTypeKind convertToEdmSimpleType(final Class jpaType, final Attribute currentAttribute) throws ODataJPAModelException Takes javax.persistence.metamodel.Attribute attribute While the calling method EdmPrimitiveTypeKind convertToEdmSimpleType(final JPAAttribute attribute) throws ODataJPAModelException has JPAAttribute This mechanism happens only when value to type conversion check is being done. While the check for Field to type is being propogated from IntermediateProperty.java [olingo-jpa-processor-v4/IntermediateProperty.java at main · SAP/olingo-jpa-processor-v4](https://github.com/SAP/olingo-jpa-processor-v4/blob/main/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/IntermediateProperty.java#L334) Where the correct Attribute type is being set. This issue, should also persist with Edm.Time.
wog48 commented 11 months ago

The issue should be solved with version 1.1.1. In case the problem still exists, reopen the issue