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

Hibernate Default schema is not detecting #265

Open suraj-mane-zellis opened 9 months ago

suraj-mane-zellis commented 9 months ago

Version - 2.0.2 and 2.0.0

I have included jar of every module of olingo-jpa-processor-v4 into our application. In this Case hibernate default schema is not detecting . hence Queries are not working . Below is the JPA property not detected when we include all modules as jars . implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))

spring.jpa.properties.hibernate.default_schema= ${DATABASE_SCHEMA:tx}

But we include our application as Module into olingo-jpa-processor-v4 then it working perfectly fine . Can you please suggest us why this is happening?

suraj-mane-zellis commented 8 months ago

Hi @wog48 ,

Can you please suggest your view on this please?

wog48 commented 5 months ago

Sorry for the late reply.

This is an issue with using odata-jpa-processor-cb, which generates native queries and Hibernate is not injecting the schema into this. So deactivate the usage of it. You service should work well. In addition I had to use spring.jpa.properties.hibernate.default_schema: your_scheme as described in change-database-schema-used-by-spring-boot.

suraj-mane-zellis commented 5 months ago

Hi @wog48 , No Problem . I have tried this spring.jpa.properties.hibernate.default_schema: your_scheme as well but issue not resolved . But after I had set entity manger into JPAODataRequestContext and its Working fine.

JPA processor Code : https://github.com/SAP/olingo-jpa-processor-v4/blob/main/jpa-tutorial/QuickStart/QuickStart.adoc

@RequestMapping(value = "**", method = { RequestMethod.GET, RequestMethod.PATCH,
      RequestMethod.POST, RequestMethod.DELETE })
  public void crud(final HttpServletRequest req, final HttpServletResponse resp) throws ODataException {

    new JPAODataRequestHandler(serviceContext, requestContext).process(req, resp);
  }

Changes in my Code :

 public void getProcess(HttpServletRequest request, HttpServletResponse response) throws ODataException {
        final JPAODataRequestHandler handler = new JPAODataRequestHandler(serviceContext, requestContext);
        handler.getRequestContext().setEntityManager(em);
        handler.process(request, response);
       }
wog48 commented 5 months ago

Let me try to explain what happens under the hood:

Module odata-jpa-processor-cb contains a wrapper for an entity manager as well as an extended implementation of the criteria builder. When the module is in the dependencies, the JPA Processor will make use of the wrapper behind the scene. With that, parameterized native queries get generated and forwarded to Hibernate and so the Hibernate default schema is not used. With your adoption, you replace the wrapper with a Hibernate entity manager and so criteria queries are provided to Hibernate and Hibernate respects the default schema. You would achieve the same by removing the dependency to odata-jpa-processor-cb.