Java.lang.IllegalArgumentException: No PersistenceProvider parameter specified in EntityManagerFactory configuration

I created a maven project and added Spring4, Hibernate4 libs via pom.xml I am trying to link my web application to my database created in PostgreSql , but when I publish my project in apache tomcat 7 , the following exception occurs:

org.springframework.beans.factory.BeanCreationException: error creating a bean with the name "emf" defined in the ServletContext resource [/WEB-INF/applicationContext.xml]: the init method call failed; Nested exception - java.lang.IllegalArgumentException: No PersistenceProvider, EntityManagerFactory specified in configuration and the selected PersistenceUnitInfo does not indicate the name of the vendor class or org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.java:1553) in org. springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.javahaps39) in org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.breventBeaveBapanBeanBeanBeanBeanBeanBeanBeanButan AbstractBeanFactory $ 1.getObject (AbstractBeanFactory.java:304) in org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:228) in org.springframework.beans.factory.srort.uppory actBeanFactory.doGetBean (AbstractBeanFactory.java{00) in org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:195) in org.springframework.context.support.AbstractApplicationConc in org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java:750) in org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java shall82Cref.opeb (ContextLoader.java:403) in org.springframework.web.context.ContextLoader.initWebApplicationContext (ContextLoader.java:306) in org.springframework.web.context.ContextLoaderListener.contextInitialized (ContextLoaderListener6avaapava.avaap.orgapava.ava catalina.core.StandardContext.listenerStart (StandardContext.java:4994) in org.apache.catalina.core.StandardContext.startInternal (Sta ndardContext.java//492) in org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java:150) in org.apache.catalina.core.ContainerBase $ StartChild.call (ContainerBase.java:1575) in org.apache .catalina.core.ContainerBase $ StartChild.call (ContainerBase.java:1565) in java.util.concurrent.FutureTask.run (Unknown source) in java.util.concurrent.ThreadPoolExecutor.runWorker (Unknown source) in java.util. concurrent.ThreadPoolExecutor $ Worker.run (Unknown source) in java.lang.Thread.run (Unknown source) Caused by: java.lang.IllegalArgumentException: there is no PersistenceProvider pointer in the EntityManagerFactory configuration and PersistenceUnitInfo selected does not specify the provider class name nor the work class frame .orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory (LocalContainerEnt ityManagerFactoryBean.java{1818) in org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet (AbstractEntityManagerFactoryBean.javahaps18) in org.springframeworkutodiveututaneututaneututaneututaneututaneututanoututuutuutuut.owansutfact.owansutoryutowututwutter .beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.java:1549) ... 21 more

here is my applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"> <context:component-scan base-package="com.medsoft.stadto"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="org.postgresql.Driver" /> <property name="url" value="jdbc:postgresql://localhost:1993/Posts" /> <property name="username" value="postgres" /> <property name="password" value="123" /> </bean> <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="emf"> <property name="packagesToScan" value="com.medsoft.stadto.entity" /> <property name="dataSource" ref="dataSource" /> <property name="jpaProperties"> <props> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2dll.auto">create</prop> </props> </property> </bean> <tx:annotation-driven transaction-manager="txManager" /> <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> </beans> 
+6
source share
1 answer

Change the emf bean configuration and add a new bean called jpaVendorAdapter :

 <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="emf"> <property name="packagesToScan" value="com.medsoft.stadto.entity" /> <property name="dataSource" ref="dataSource" /> <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/> <property name="persistenceUnitName" value="stadto"/> <property name="jpaProperties"> <props> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">create</prop> </props> </property> </bean> <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="true"/> <property name="generateDdl" value="true"/> <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect"/> </bean> 

Also make sure you have persistence.xml in the META-INF :

 <?xml version="1.0"?> <persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" version="2.1"> <persistence-unit name="stadto"> //No need to specify the provider as we already have specified JPA vendor in applicationContext.xml </persistence-unit> </persistence> 
+11
source

All Articles