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

How to implement user defined function using eclipselink ? #242

Closed suraj-mane-zellis closed 10 months ago

suraj-mane-zellis commented 10 months ago

As suggested in issue - https://github.com/SAP/olingo-jpa-processor-v4/issues/238 . I have exclude hibernate and use eclipse library for jpa implementation . We had implement custom function which supported in hibernate and how we can implement same in eclipse link

Implementation with Hibernate :

      import org.hibernate.boot.MetadataBuilder;
      import org.hibernate.dialect.function.SQLFunctionTemplate;
      import org.hibernate.type.StandardBasicTypes;

  public class TestMetadataBuilderContributor {

  public static void commonSqlFunctions(MetadataBuilder metadataBuilder) {
    metadataBuilder.applySqlFunction("cast_as_time", new SQLFunctionTemplate(StandardBasicTypes.TIME,
            "cast(?1 as time)"));
    metadataBuilder.applySqlFunction("cast_as_date", new SQLFunctionTemplate(StandardBasicTypes.DATE,
            "cast(?1 as date)"));

             }
         }

olingo-jpa-processor-v4 - Custom implementation in JPAOperationConverter.class

 case DATE:

  return cb.function("cast_as_date", Date.class, (Expression<Timestamp>) jpaFunction.getParameter(0).get());

I have gone through eclipse link official document , I have found something .

https://wiki.eclipse.org/Introduction_to_EclipseLink_Expressions_(ELUG)#Creating_and_Using_a_User-Defined_Function

Can you please provide how we can implement database specific custom function in jpa processor side using eclipse link?

wog48 commented 10 months ago

Actually, I'm not sure if I can help. I never tried to add a database function to the JPA Metadata. Nevertheless, with version 2.0.2 the problems with Hibernate shall be solved and you can try to use it again.

In case you like to find ut, how you can make use of database function with in OData request, you may find Functions helpful.