未找到持久性 JPA [重复]

JPA no persistence found [duplicate]

提问人:jhonny 提问时间:11/16/2023 最后编辑:jhonny 更新时间:11/16/2023 访问量:72

问:

首先,我不认为这是重复的,因为我检查了文件夹名称以及持久性名称文件

我更新了 pom 以使用 maven。

  <dependencies>
      
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    
    <!-- JPA -->
    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>javax.persistence-api</artifactId>
        <version>2.2</version>
    </dependency>

    <!-- Hibernate (JPA Implementation) -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.5.6.Final</version>
        <scope>compile</scope>
    </dependency>

    <!-- Derby -->
    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derby</artifactId>
        <version>10.15.2.0</version>
    </dependency>
    
  </dependencies>

我仍然没有得到未找到的持久性

请查看图片了解更多背景信息

<persistence-unit name="Memories" transaction-type="RESOURCE_LOCAL">

这是数据模型

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import com.fcul.memoriesdb.domain.Photograph;

import java.util.List;
 
public class PhotographDataMapper {
 
    private EntityManagerFactory entityManagerFactory;
 
    public PhotographDataMapper() {
        // Create the EntityManagerFactory
        entityManagerFactory = Persistence.createEntityManagerFactory("Memories");
Java Maven JPA

评论

1赞 Reg 11/16/2023
嘿!请将错误消息添加为文本而不是图像:)
0赞 Janez Kuhar 11/16/2023
如果您已经配置了与 MySQL DB 服务器的连接,为什么要使用?我认为您应该包含对 ConnectorJ 的依赖关系。org.apache.derby:derby:10.15.2.0persistence.xml
0赞 Janez Kuhar 11/16/2023
在你的 中,如果你打算使用 Hibernate,你为什么要配置为你的提供者?我很确定你希望这样.persistence.xmlorg.eclipse.persistence.jpa.PersistenceProviderorg.hibernate.jpa.HibernatePersistenceProvider

答:

0赞 Lesiak 11/16/2023 #1

JPA 规范的实现包括:

  • 冬眠
  • EclipseLink的

您导入了 Hibernate JAR,但指定了 EclipseLink 作为 JPA 提供程序:

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

请改用 Hibernate 提供程序:

<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

评论

0赞 jhonny 11/16/2023
如果我想使用 eclipseLink 作为我的 jpa 提供程序,我该怎么办?我不需要 Hibernate
0赞 Lesiak 11/16/2023
然后在你的 pom 中将 org.hibernate:hibernate-core 替换为 org.eclipse.persistence:eclipselink。在 mvnrepository.com/artifact/org.eclipse.persistence/eclipselink/ 查看神器...
0赞 jhonny 11/16/2023
它仍然执行相同的错误,如果您想查看它,我可以将文件发送给您