【发布时间】:2014-03-03 01:03:23
【问题描述】:
我收到此错误:
线程“main”中的异常 javax.persistence.PersistenceException:没有名为 EmployeeDb 的 EntityManager 的持久性提供程序 在 javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85) 在 javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54) 在 staffManagement.test.TestHarness.main(TestHarness.java:14)
但我就是不明白为什么——我在家用电脑上做了同样的事情并且没有任何问题。这是我的测试文件的代码:
public class TestHarness {
public static void main(String[] args) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("EmpDb");
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
Employee employee1 = new Employee("Brad", "Pitt", "Actor", 10000);
em.persist(employee1);
tx.commit();
em.close();
}
}
还有我的 persistence.xml 文件:
<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"
version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="EmpDb" transaction-type="RESOURCE_LOCAL">
<class>staffManagement.domain.Employee</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/DbName" />
<property name="javax.persistence.jdbc.user" value="APP" />
<property name="javax.persistence.jdbc.password" value="APP" />
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
请帮帮我!我在扯我的头发。我正在使用 Eclipse 和 Derby 数据库。我在 meta-inf 文件夹中有 persistence.xml 文件。
【问题讨论】:
标签: jakarta-ee jpa eclipselink