Open suraj-mane-zellis opened 9 months ago
Hi @wog48 ,
Can you please suggest your view on this please?
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.
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);
}
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
.
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?