I need some help with jpa configuration in spring.
I use spring, spring data and hibernate in the application. I have some problem with the configuration. It can create the tables in the database so this part works. But when I try to save a test object, I get an exception.
The spring uses this application-context.xml:
This is the exception what I get:
Error creating bean with name 'entityManagerFactory' defined in class path resource [application-context.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No PersistenceProvider specified in EntityManagerFactory configuration, and chosen PersistenceUnitInfo does not specify a provider class name either
I understand that the PersistenceProvider is missing but I don't know how to solve it.
I tried to find examples and follow them, but I couldn't solve it.
You need to put persistence.xml in META-INF directory, or you need to declare your PersistenceUnitManager in the spring xml
posted 6 years ago
I tried to follow your advice, but it is not absolutely clear for me. I still couldn't find a good example for it. Can I ask more help?
I don't use persistence.xml. I don't want to create more xml than absolutely necessary so I want to put this into the xml of spring.
Could you show me an example? Don't I have any possibility to put every configuration into the sesionFactory without the entityManagerFactory?
Have you tried going through the spring documentation for JPA here? THis shows you how to setup your EMF.
Since you are using Spring Data, you just have to declare the repositories xml tag to make it scan the class path for Spring Data repositories, and autowire the EMF into them.
You can look at the examples that Spring Data provides here , but all (I think) of these examples shy away from XML based configuration, and just use annotation driven configuration. The main example uses all defaults, so they don't provide anything in the configuration. All the do is put persistence.xml in classpath. Spring does all it's behind the scenes magic to create the EMF. Unfortunately, it doesn't help you understand how it really works.
Blueberry pie is best when it is firm and you can hold in your hand. Smell it. And smell this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!