Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Olingo 4 without persistence.xml

former_member662510
Discoverer
0 Kudos
692

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".


Thanks
3 REPLIES 3

jerryjanda
Community Manager
Community Manager
0 Kudos
292

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

Make sure to subscribe to What's New!

former_member662510
Discoverer
0 Kudos
292

i resolved like this:

final JPAODataCRUDContextAccess serviceContextB = JPAODataServiceContext.with()
          .setPUnit("default")
          .setDataSource(dc)
          .setTypePackage("my.package.model")
          .setEntityManagerFactory(em.getEntityManagerFactory())
          .build();

nic_botha2
Advisor
Advisor
0 Kudos
292

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.