|
|
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 quot;No Persistence provider for EntityManager named craigPersistenceUnitquot;. 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 irectory 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:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot; standalone=quot;noquot;?gt;
lt;beans xmlns=quot;schema/beansquot; xmlns:tx=quot;schema/txquot; xmlns:context=quot;schema/contextquot; xmlns:xsi=quot;2001/XMLSchema-instancequot; xsi:schemaLocation=quot;schema/beans schema/beans/spring-beans-3.0.xsd schema/context schema/context/spring-context-3.0.xsd schema/tx schema/tx/spring-tx-3.0.xsdquot;gt;
lt;context:component-scan base-package=quot;craig.testquot; /gt;
lt;context:property-placeholder location=quot;classpath*:spring-config/*.propertiesquot; /gt;
lt;bean id=quot;entityManagerFactoryquot;
class=quot;org..orm.jpa.LocalEntityManagerFactoryBeanquot;gt;
lt;property name=quot;persistenceUnitNamequot; value=quot;craigPersistenceUnitquot; /gt;
lt;/beangt;
lt;bean id=quot;transactionManagerquot; class=quot;org..orm.jpa.JpaTransactionManagerquot;gt;
lt;property name=quot;entityManagerFactoryquot; ref=quot;entityManagerFactoryquot; /gt;
lt;/beangt;
lt;tx:annotation-driven transaction-manager=quot;transactionManagerquot;/gt;
lt;/beansgt;
And here is my persistence.xml:Code:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot; standalone=quot;noquot;?gt;
lt;persistence xmlns=quot;xml/ns/persistencequot;
xmlns:xsi=quot;2001/XMLSchema-instancequot;
xsi:schemaLocation=quot;xml/ns/persistence xml/ns/persistence/persistence_2_0.xsdquot;
version=quot;2.0quot;gt;
lt;persistence-unit name=quot;craigPersistenceUnitquot;
transaction-type=quot;RESOURCE_LOCALquot;gt;
lt;propertiesgt;
lt;property name=quot;hibernate.connection.driver_classquot; value=quot;oracle.jdbc.driver.OracleDriverquot; /gt;
lt;property name=quot;hibernate.connection.uclquot; value=quot;jdbc racle:thin localhost:1521:XEquot; /gt;
lt;property name=quot;hibernate.dialectquot; value=quot;org.hibernate.dialect.OracleDialectquot; /gt;
lt;property name=quot;hibernate.connection.usernamequot; value=quot;findlawquot; /gt;
lt;property name=quot;hibernate.connection.passwordquot; value=quot;passwordquot; /gt;
lt;property name=quot;hibernate.default_schemaquot; value=quot;findlawquot; /gt;
lt;property name=quot;hibernate.show_sqlquot; value=quot;truequot; /gt;
lt;property name=quot;hibernate.current_session_context_classquot; value=quot;threadquot; /gt;
lt;property name=quot;hibernate.hbm2ddl.autoquot; value=quot;updatequot; /gt;
lt;/propertiesgt;
lt;/persistence-unitgt;
lt;/persistencegt;
Any thoughts on what is going on? Any suggestions for troubleshooting? Thanks.
Craig
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?
Originally Posted by amiladomingoYou 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..beans.factory.BeanCreationExce ption: Error creating bean with name 'personDao': Injection of persistence dependencies failed; nested exception is org..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..orm.jpa.support.PersistenceAnn otationBeanPostProcessor.postProcessPropertyValues (PersistenceAnnotationBeanPostProcessor.java:341)
at org..beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1074)
at org..beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:517)
at org..beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
at org..beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91)
at org..beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
at org..beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 )
at org..beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
at org..beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:580)
at org..context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:895)
at org..context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:425)
at org..context.support.ClassPathXmlAp plicationContext.lt;initgt;(ClassPathXmlApplicationCon text.java:139)
at org..context.support.ClassPathXmlAp plicationContext.lt;initgt;(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..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..beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1420)
at org..beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:519)
at org..beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
at org..beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91)
at org..beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
at org..beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 )
at org..beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
at org..orm.jpa.support.PersistenceAnn otationBeanPostProcessor.findDefaultEntityManagerF actory(PersistenceAnnotationBeanPostProcessor.java :529)
at org..orm.jpa.support.PersistenceAnn otationBeanPostProcessor.findEntityManagerFactory( PersistenceAnnotationBeanPostProcessor.java:495)
at org..orm.jpa.support.PersistenceAnn otationBeanPostProcessor$PersistenceElement.resolv eEntityManager(PersistenceAnnotationBeanPostProces sor.java:656)
at org..orm.jpa.support.PersistenceAnn otationBeanPostProcessor$PersistenceElement.getRes ourceToInject(PersistenceAnnotationBeanPostProcess or.java:629)
at org..beans.factory.annotation.Injec tionMetadata$InjectedElement.inject(InjectionMetad ata.java:156)
at org..beans.factory.annotation.Injec tionMetadata.inject(InjectionMetadata.java:84)
at org..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..orm.jpa.LocalEntityManagerFact oryBean.createNativeEntityManagerFactory(LocalEnti tyManagerFactoryBean.java:92)
at org..orm.jpa.AbstractEntityManagerF actoryBean.afterPropertiesSet(AbstractEntityManage rFactoryBean.java:308)
at org..beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1477)
at org..beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1417)
... 41 more
Few things to verify,
1. Is your persistence.xml in a place that is accessible to the unit test
2. Did you try adding lt;providergt; for the persistence-unitCode:
lt;providergt;org.hibernate.ejb.HibernatePersistencelt;/providergt;
I'm not that sure if the second problem can cause that exception. But just to be sure
I rearranged the config to use a datasource instead and the error was more clear at that point. I had forgotten the Oracle dependency. |
|