No Persistence provider for EntityManager named

前端 未结 30 2052
甜味超标
甜味超标 2020-11-22 03:45

I have my persistence.xml with the same name using TopLink under the META-INF directory. Then, I have my code calling it with:

相关标签:
30条回答
  • 2020-11-22 04:44

    Mine got resolved by adding info in persistence.xml e.g. <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> and then making sure you have the library on classpath e.g. in Maven add dependency like

    <dependency>
      <groupId>org.eclipse.persistence</groupId>
      <artifactId>eclipselink</artifactId>
      <version>2.5.0</version>
    </dependency>
    
    0 讨论(0)
  • 2020-11-22 04:46

    There is another point: If you face this problem within an Eclipse RCP environment, you might have to change the Factory generation from Persistence.createEntityManagerFactory to new PersistenceProvider().createEntityManagerFactory

    see ECF for a detailed discussion on this.

    0 讨论(0)
  • 2020-11-22 04:46

    If you are using Eclipse make sure that exclusion pattern does not remove your persistence.xml from source folders on build path.

    1. Go to Properties -> Java Build Path -> Source tab
    2. Check your exclusion pattern which is located at
      MyProject/src/main/java -> Excluded: <your_pattern>
      tree node
    3. Optionally, set it to Excluded: (None) by selecting the node and clicking Edit... button on the left.
    0 讨论(0)
  • 2020-11-22 04:46

    Had the same issue, but this actually worked for me :

    mvn install -e  -Dmaven.repo.local=$WORKSPACE/.repository.
    

    NB : The maven command above will reinstall all your project dependencies from scratch. Your console will be loaded with verbose logs due to the network request maven is making.

    0 讨论(0)
  • 2020-11-22 04:47

    I just copied the META-INF into src and worked!

    0 讨论(0)
  • 2020-11-22 04:47

    Verify the peristent unit name

    <persistence-unit name="com.myapp.model.jpa"
        transaction-type="RESOURCE_LOCAL">    
    public static final String PERSISTENCE_UNIT_NAME = "com.myapp.model.jpa";
    Persistence.createEntityManagerFactory(**PERSISTENCE_UNIT_NAME**);
    
    0 讨论(0)
提交回复
热议问题