我使用persistense API連接到數據庫沒有持久性提供 「EntityManager的」 命名 「firstOne的」 Java
這是pom.xml的dependendcies
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.8.Final</version>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
persistense.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_1_0.xsd"
version="1.0">
<persistence-unit name="firstOne">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.ejb.cfgfile" value="/META-INF/hibernate.cfg.xml" />
</properties>
</persistence-unit>
</persistence>
的hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">tauren993</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/hibernate</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="hibernate.generate_statistics">false</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hibernate.cache.use_structured_entries">false</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<mapping class="Employee" />
</session-factory>
</hibernate-configuration>
的hibernate.cfg.xml和persistense.xml存儲項目/ META-INF文件夾,然後我得到的
EntityManagerFactory emf = Persistence.createEntityManagerFactory("firstOne");
堆棧跟蹤錯誤:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named firstOne
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at Main.main(Main.java:14)
請提供錯誤的完整堆棧跟蹤。 – david99world
javax.persistence.PersistenceException:在javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)爲EntityManager的不持久性提供者在javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)命名firstOne \t \t \t在Main.main(Main.java:14) – luka