【问题标题】:JPA persistence.xml not found找不到 JPA persistence.xml
【发布时间】:2014-01-22 10:13:01
【问题描述】:

我知道以前有人问过这个问题,但我仍然无法让 JPA 处理我的项目。 我收到 PersistenceException No provider found。 我的 src/main/resources/META-INF 文件夹中有 persistence.xml,我使用 m2 进行构建,但持久性文件没有移至构建目录。

这是我的 persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>com.entities.User</class>
    <class>com.entities.Group</class>
    <properties>
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/BandwidthX"/>
        <property name="javax.persistence.jdbc.password" value="password"/>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
        <property name="javax.persistence.jdbc.user" value="root"/>
    </properties>
</persistence-unit>

我正在尝试坚持使用此代码:

EntityManagerFactory emf =
        Persistence.createEntityManagerFactory("test");
    EntityManager em = emf.createEntityManager();

【问题讨论】:

    标签: jpa jdbc


    【解决方案1】:

    persistence.xml 应该在 src/main/resources/META-INF 文件夹中,这样构建才能正常工作。

    请参阅the JPA spec 的第 8.2.1 节。

    【讨论】:

    • 啊,好的。让事情变得不太清楚。您能否列出您执行的 maven 命令并检查生成的 .war 文件的内容?
    猜你喜欢
    • 2015-08-08
    • 1970-01-01
    • 2015-09-10
    • 2019-11-25
    • 1970-01-01
    • 1970-01-01
    • 2010-11-19
    • 2011-06-18
    • 1970-01-01
    相关资源
    最近更新 更多