0

I get this exception when I try to run my test web application:

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'myDAO': 
Injection of persistence dependencies failed; 
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'emf' defined in ServletContext resource 
[/WEB-INF/testapp-servlet.xml]:
Invocation of init method failed; 
nested exception is javax.persistence.PersistenceException: 
No Persistence provider for EntityManager named testapp

My persistence.xml file is in META-INF folder:

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence      http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="testapp" transaction-type="RESOURCE_LOCAL">
    <class>it.testapp.entities.Person</class>
    <class>it.testapp.entities.Group</class>
    <properties>
        <property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
        <property name="javax.persistence.jdbc.url"
            value="jdbc:sqlserver://localhost;databaseName=db_testapp" />
        <property name="javax.persistence.jdbc.user" value="user1" />
        <property name="javax.persistence.jdbc.password" value="" />
    </properties>

</persistence-unit>

My data-context.xml bean definiton file is into WEB-INF folder:

<?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"
xsi:schemaLocation="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-3.1.xsd">


<context:annotation-config />
<context:component-scan base-package="it.testapp.dao" />

<bean id="emf"
    class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="testapp"></property>
</bean>

<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

<bean id="aDao" class="it.testapp.dao.jpa.PersonJpaDAO" />

Where is the problem?

2

1 Answer 1

1

Do you need to add a <provider> tag under <persistence-unit>?

(e.g. <provider>org.hibernate.ejb.HibernatePersistence</provider>)

Also, this answer suggested that not having your persistence.xml in /WEB-INF/classes/META-INF might also trigger this error.

Sign up to request clarification or add additional context in comments.

3 Comments

It's not a different exception or anything? If not, is org.hibernate.ejb.HibernatePersistence in your classpath?
Same exception... I'm using Hibernate 4, so have hibernate-entitymanager-4.1.1.Final.jar in my classpath
Sorry, the problem was that my persistence.xml was in /WebContent/META_INF (I'm using Eclipse) and not into /src/META-INF. Thank you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.