This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Error creating a bean, injection of persistence dependencies failed  RSS feed

 
Ranch Hand
Posts: 1709
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am running an example here: https://www.boraji.com/spring-4-hibernate-5-jpa-2-integration-example
In pom.xml, I am using spring version 5.0.3 instead of version 4 and I am using derby client instead of MySQL connector.


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.boraji.tutorial.hibernate</groupId>
 <artifactId>spring-hibernate-jpa-example</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>jar</packaging>
 <build>
   <sourceDirectory>src/main/java</sourceDirectory>
   <plugins>
     <plugin>
       <artifactId>maven-compiler-plugin</artifactId>
       <version>3.7.0</version>
       <configuration>
         <source>1.8</source>
         <target>1.8</target>
       </configuration>
     </plugin>
   </plugins>
 </build>
 <dependencies>
   <!-- Spring Context -->
   <dependency>
     <groupId>org.springframework</groupId>
     <artifactId>spring-context</artifactId>
     <version>5.0.3.RELEASE</version>
   </dependency>
   <!-- Spring ORM -->
   <dependency>
     <groupId>org.springframework</groupId>
     <artifactId>spring-orm</artifactId>
     <version>5.0.3.RELEASE</version>
   </dependency>
   <!-- derby client -->
   <dependency>
     <groupId>org.apache.derby</groupId>
     <artifactId>derbyclient</artifactId>
     <version>10.14.2.0</version>
   </dependency>
   <!-- Hibernate 5.2.9 Final -->
   <dependency>
     <groupId>org.hibernate</groupId>
     <artifactId>hibernate-core</artifactId>
     <version>5.2.9.Final</version>
   </dependency>
   <!-- Apache Commons DBCP -->
   <dependency>
     <groupId>org.apache.commons</groupId>
     <artifactId>commons-dbcp2</artifactId>
     <version>2.1.1</version>
   </dependency>
 </dependencies>
</project>


This is my persistence.xml. (My username and password are ok to share since it is just for exercise.)


<?xml version="1.0" encoding="UTF-8"?>
<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="LOCAL_PERSISTENCE">
   <description> Spring Hibernate JPA Configuration Example</description>
   <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

   <properties>
     <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver" />
     <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/myDB;create=true" />
     <property name="javax.persistence.jdbc.user" value="user" />
     <property name="javax.persistence.jdbc.password" value="user" />
     <property name="hibernate.show_sql" value="true" />
     <property name="hibernate.hbm2ddl.auto" value="update" />
   </properties>

 </persistence-unit>
</persistence>


But I got this error:


Jun 15, 2018 5:52:19 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@b1a58a3: startup date [Fri Jun 15 17:52:19 EDT 2018]; root of context hierarchy
Jun 15, 2018 5:52:19 PM org.springframework.orm.jpa.LocalEntityManagerFactoryBean createNativeEntityManagerFactory
INFO: Building JPA EntityManagerFactory for persistence unit 'LOCAL_PERSISTENCE'
Jun 15, 2018 5:52:19 PM org.springframework.context.support.AbstractApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDaoImp': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'geEntityManagerFactoryBean' defined in com.boraji.tutorial.spring.config.AppConfig: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: No Persistence provider for EntityManager named LOCAL_PERSISTENCE
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDaoImp': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'geEntityManagerFactoryBean' defined in com.boraji.tutorial.spring.config.AppConfig: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: No Persistence provider for EntityManager named LOCAL_PERSISTENCE
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:355)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1344)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)

 ....
at com.boraji.tutorial.spring.MainApp.main(MainApp.java:18)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'geEntityManagerFactoryBean' defined in com.boraji.tutorial.spring.config.AppConfig: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: No Persistence provider for EntityManager named LOCAL_PERSISTENCE
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1710)
....
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named LOCAL_PERSISTENCE
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at org.springframework.orm.jpa.LocalEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalEntityManagerFactoryBean.java:96)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:388)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1769)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706)
... 27 more



I started my Derby DB already. Please help. Thanks.
fileStructure.JPG
[Thumbnail for fileStructure.JPG]
Maven file structure
 
Himai Minh
Ranch Hand
Posts: 1709
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I searched online and got an advice. Someone suggested to remove the directories under .m2/repository/org/springframework. I did that. But  now. when I run the MainApp.java, I got an error.
I should not remove them.


Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/AliasRegistry
at java.lang.ClassLoader.defineClass1(Native Method)
...
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.boraji.tutorial.spring.MainApp.main(MainApp.java:17)
Caused by: java.lang.ClassNotFoundException: org.springframework.core.AliasRegistry
at java.net.URLClassLoader.findClass(Unknown Source)


 
Himai Minh
Ranch Hand
Posts: 1709
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I finally removed my Eclipse and reinstalled it. I also removed .m2 directory. Then, it works.
 
Bartender
Posts: 1868
81
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for sharing your story along with your solution.
I know you are done with this, but could you please provide the following info:
  • Operating system
  • Java version
  • Eclipse version
      - STS version

  • I suppose it doesn't matter now, but I wonder if the problem was with Eclipse or the .m2 directory.
    There is a possibility that using IntelliJ might have solved this problem as well or possibly using Gradle instead of Maven.

    Just a thought or two,
    Pete
     
    Himai Minh
    Ranch Hand
    Posts: 1709
    12
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    This is the information:
    Operating system : Window 10
    Java version: 8
    Eclipse : Oxygen 3A
    I don't install STS plugin for Eclipse.
    My lesson I learnt is  not remove repository folder of .m2 directory. I took the advice to remove repository folder, but I got the above error in creating a bean.
     
    Pete Letkeman
    Bartender
    Posts: 1868
    81
    Android Chrome IntelliJ IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    For being so through and for solving the problem you get a cow.
     
    If tomatoes are a fruit, then ketchup must be a jam. Taste this tiny ad:
    RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
    https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!