我得到這個錯誤:在線程「主要」 javax.persistence.PersistenceException沒有持久性提供EntityManager的命名EmpDb
例外:否EntityManager的持久性提供者在javax.persistence.Persistence.createEntityManagerFactory命名EmployeeDb ( 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 db。我有meta-inf文件夾中的persistence.xml文件。
看到我更新的答案。 –
[Persistence.createEntityManagerFactory(PERSISTENCE \ _UNIT \ _NAME);](http:// stackoverflow。COM /問題/ 19322827 /空後的持久性,createentitymanagerfactorypersistence單位名稱) – cmd