2020 Feb 24 7:46 PM
Hi all,
is it possible to use the SAP odata-jpa-processor lib (0.3.7-SNAPSHOT) having spring-boot without having a persistence.xml?
I'm trying to create a Class controller with @RestController and i get the EntityManager,DataSource, and ServletContext from spring context but JPAODataCRUDContextAccess needs setPUnit:
@RestController
@RequestMapping(SapController.URI)
public class SapController {
public static final String URI = "/odata";
@Autowired
EntityManager em;
@Autowired
DataSource dc;
@Autowired
ServletContext context;
@RequestMapping(value = "*")
public void process(HttpServletRequest request, HttpServletResponse response) throws ODataException {
final JPAODataCRUDContextAccess serviceContext = JPAODataServiceContext.with()
.setPUnit("default")
.setDataSource(dc)
.setTypePackage("my.package.model")
.build();
final JPAODataCRUDHandler handler = new JPAODataCRUDHandler(serviceContext);
handler.getJPAODataRequestContext().setEntityManager(em);
handler.process(request, response);
handler.process(new HttpServletRequestWrapper(request) {
@Override
public String getServletPath() {
return SapController.URI;
}
}, response);
}
}
If i set Punit with a "random name" i received the error "javax.persistence.PersistenceException: No Persistence provider for EntityManager named default".
2020 Feb 24 7:47 PM
Thank you for visiting SAP Community to get answers to your questions. Since you're asking a question here for the first time, I recommend that you familiarize yourself with https://community.sap.com/resources/questions-and-answers (if you haven't already), as it provides tips for preparing questions that draw responses from our members.
Should you wish, you can revise your question by selecting Actions, then Edit (although once someone answers your question, you'll lose the ability to edit the question -- but if that happens, you can leave more details in a comment).
--Jerry
2020 Feb 26 3:13 PM
2021 Aug 23 12:52 AM
Also, have a look at the archetype prototype which shows a spring boot example - https://github.com/SAP/olingo-jpa-processor-v4/tree/develop/jpa-archetype/jpa-archetype-spring/src/m.... ProcessorConfiguration.java shows how to achieve this.