Announcement Announcement Module
Collapse
No announcement yet.
No Persistence provider with Maven build Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • No Persistence provider with Maven build

    I have a sample application that works fine as a plain old java project in Eclipse but when I set up a Maven project for it, I'm getting a "No Persistence provider for EntityManager named craigPersistenceUnit". My thought was that it was unable to find the META-INF/persistencce.xml file so I print out the classpath in the test. That prints out, among other things:

    /C:/dev/eclipse/hibernate/SpringHibernateMaven/target/test-classes/
    /C:/dev/eclipse/hibernate/SpringHibernateMaven/target/classes/

    Just to be safe, I included those files in both the test and main directories and it does get copied over.

    Code:
     Directory of C:\dev\eclipse\hibernate\SpringHibernateMaven\target\classes\META-INF
    
    01/14/2011  04:14 PM             1,150 persistence.xml
                   1 File(s)          1,150 bytes
    
     Directory of C:\dev\eclipse\hibernate\SpringHibernateMaven\target\test-classes\META-INF
    
    01/14/2011  04:23 PM             1,152 persistence.xml
                   1 File(s)          1,152 bytes
    Just to close the loop here is my Spring config:

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
                               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                               http://www.springframework.org/schema/context
                               http://www.springframework.org/schema/context/spring-context-3.0.xsd
                               http://www.springframework.org/schema/tx
                               http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    
    	<context:component-scan base-package="craig.test" />
    
    	<context:property-placeholder location="classpath*:spring-config/*.properties" />
    
    	<bean id="entityManagerFactory"
    		class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    		<property name="persistenceUnitName" value="craigPersistenceUnit" />
    	</bean>
    
    	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory" />
    	</bean>
    
        <tx:annotation-driven transaction-manager="transactionManager"/>
    
    </beans>
    And here is my persistence.xml:

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <persistence xmlns="http://java.sun.com/xml/ns/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">
    
    	<persistence-unit name="craigPersistenceUnit"
    		transaction-type="RESOURCE_LOCAL">
    		<properties>
    			<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />
    			<property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:XE" />
    			<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" />
    			<property name="hibernate.connection.username" value="findlaw" />
    			<property name="hibernate.connection.password" value="password" />
    			<property name="hibernate.default_schema" value="findlaw" />
    			<property name="hibernate.show_sql" value="true" />
    			<property name="hibernate.current_session_context_class" value="thread" />
    			<property name="hibernate.hbm2ddl.auto" value="update" />
    		</properties>
    	</persistence-unit>
    
    </persistence>
    Any thoughts on what is going on? Any suggestions for troubleshooting? Thanks.

    Craig

  • #2
    You get this error when you run through maven? If so, then do you do any resource exclusions in maven-compiler-plugin or maven-war-plugin?

    Comment


    • #3
      Originally posted by amiladomingo View Post
      You get this error when you run through maven? If so, then do you do any resource exclusions in maven-compiler-plugin or maven-war-plugin?
      Sorry, I should have been more specific. I get it when I run a unit test. I've included the trace from the error below:

      org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'personDao': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring-config/applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: No Persistence provider for EntityManager named craigPersistenceUnit
      at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor.postProcessPropertyValues (PersistenceAnnotationBeanPostProcessor.java:341)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1074)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:517)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
      at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91)
      at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
      at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 )
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
      at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:580)
      at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:895)
      at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:425)
      at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:139)
      at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:83)
      at craig.test.dao.PersonTest.setup(PersonTest.java:36 )
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.junit.runners.model.FrameworkMethod$1.runRefle ctiveCall(FrameworkMethod.java:44)
      at org.junit.internal.runners.model.ReflectiveCallabl e.run(ReflectiveCallable.java:15)
      at org.junit.runners.model.FrameworkMethod.invokeExpl osively(FrameworkMethod.java:41)
      at org.junit.internal.runners.statements.RunBefores.e valuate(RunBefores.java:27)
      at org.junit.runners.ParentRunner.run(ParentRunner.ja va:236)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:49)
      at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:467)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:683)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:390)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:197)
      Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring-config/applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: No Persistence provider for EntityManager named craigPersistenceUnit
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1420)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:519)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
      at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91)
      at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
      at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 )
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
      at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor.findDefaultEntityManagerF actory(PersistenceAnnotationBeanPostProcessor.java :529)
      at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor.findEntityManagerFactory( PersistenceAnnotationBeanPostProcessor.java:495)
      at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor$PersistenceElement.resolv eEntityManager(PersistenceAnnotationBeanPostProces sor.java:656)
      at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor$PersistenceElement.getRes ourceToInject(PersistenceAnnotationBeanPostProcess or.java:629)
      at org.springframework.beans.factory.annotation.Injec tionMetadata$InjectedElement.inject(InjectionMetad ata.java:156)
      at org.springframework.beans.factory.annotation.Injec tionMetadata.inject(InjectionMetadata.java:84)
      at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor.postProcessPropertyValues (PersistenceAnnotationBeanPostProcessor.java:338)
      ... 28 more
      Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named craigPersistenceUnit
      at javax.persistence.Persistence.createEntityManagerF actory(Persistence.java:89)
      at org.springframework.orm.jpa.LocalEntityManagerFact oryBean.createNativeEntityManagerFactory(LocalEnti tyManagerFactoryBean.java:92)
      at org.springframework.orm.jpa.AbstractEntityManagerF actoryBean.afterPropertiesSet(AbstractEntityManage rFactoryBean.java:308)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1477)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1417)
      ... 41 more

      Comment


      • #4
        Few things to verify,

        1. Is your persistence.xml in a place that is accessible to the unit test

        2. Did you try adding <provider> for the persistence-unit

        Code:
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        I'm not that sure if the second problem can cause that exception. But just to be sure

        Comment


        • #5
          I rearranged the config to use a datasource instead and the error was more clear at that point. I had forgotten the Oracle dependency.

          Comment

          Working...
          X