大家。我是JPA 2.0的新手。我正在使用maven和eclipse,以及eclipse链接。我在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="certifications">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.ni.apps.engineering.certification.entities.NicdsCliCertificationStg</class>
<class>com.ni.apps.engineering.certification.entities.NicdsCliCertificationStgPK</class>
<class>com.ni.apps.engineering.certification.entities.NicdsCliUpMapping</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@localhost:5455:orcl"/>
<property name="javax.persistence.jdbc.password" value="ni"/>
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
<property name="javax.persistence.jdbc.user" value="NI"/>
<property name="eclipselink.logging.level.sql" value="FINE"/>
</properties>
</persistence-unit>
</persistence>
我在外观中使用此代码来获取实体管理器。
private EntityManagerFactory emf;
protected EntityManager getEntityManager(){
if(emf == null){
emf = Persistence.createEntityManagerFactory("certifications");
}
return emf.createEntityManager();
}
当我到达这个部分时,它总是返回“没有为EntityManager命名认证的持久性提供程序”。我确保persistence.xml在META-INF中,而META-INF是类路径的一部分。有任何想法吗?谢谢!
- EDIT-- Stacktrace添加了
Exception in thread "main" com.ni.apps.engineering.certification.exception.CertificationException: Internal Server Error
at com.ni.apps.engineering.certification.controller.AbstractFacade.getContactIdByUpId(AbstractFacade.java:28)
at com.ni.apps.engineering.certification.controller.CertificationFacade.getCertificationsByUpId(CertificationFacade.java:14)
at com.ni.apps.engineering.certification.dao.CertificationDAO.getCertificationByUpId(CertificationDAO.java:13)
at Main.main(Main.java:9)
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named certifications
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at com.ni.apps.engineering.certification.controller.AbstractFacade.getEntityManager(AbstractFacade.java:17)
at com.ni.apps.engineering.certification.controller.AbstractFacade.getContactIdByUpId(AbstractFacade.java:25)