javax.ejb.EJBException:javax.ejb.CreateException:Singleton EntityManagerFactory的初始化失败

时间:2018-04-20 17:06:05

标签: java xml jpa glassfish

当我尝试在我的任何bean中使用我的实体管理器时,我收到以下错误消息:

  

javax.ejb.EJBException:javax.ejb.CreateException:Singleton EntityManagerFactory的初始化失败`

错误的另一部分是:

  

没有名为Assignment3JPAProvider的EntityManager的持久性提供程序

的persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="Assignment3JPAProvider">


 <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <class>prog3060.entities.Age</class>
    <class>prog3060.entities.AgeGroup</class>
    <class>prog3060.entities.CensusYear</class>
    <class>prog3060.entities.GeographicArea</class>
    <class>prog3060.entities.Household</class>
    <class>prog3060.entities.HouseholdEarners</class>
    <class>prog3060.entities.HouseholdsByAgeRange</class>
    <class>prog3060.entities.HouseholdSize</class>
    <class>prog3060.entities.HouseholdType</class>
    <class>prog3060.entities.TotalIncome</class>
    <properties>
        <property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.ClientDriver"/>
        <property name="hibernate.connection.url" value="jdbc:derby://localhost:1527/CensusDB"/>
        <property name="hibernate.default_schema" value="APP"/>
        <property name="hibernate.connection.username" value="user"/>
        <property name="hibernate.connection.password" value="123"/>
        <property name="hibernate.connection.pool_size" value="10"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyTenSevenDialect"/>
    </properties>
</persistence-unit>

EntityManagerFactory的:

package prog3060.beans;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.LocalBean;
import javax.ejb.Singleton;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;

@Singleton
@LocalBean
public class EntityManagerFactory implements EntityManagerFactoryLocal {

    javax.persistence.EntityManagerFactory emf;


    @Override
    public EntityManager getEntityManager() {

        return emf.createEntityManager();
    }

    @PostConstruct
    void initialize() {
        emf = Persistence.createEntityManagerFactory("Assignment3JPAProvider");
    }

    @PreDestroy
    void destroy() {
        emf.close();
    }



}

这是使用glassfish5和jpa。这次崩溃的原因是什么?每当我尝试使用实体管理器时都会发生这种情况。

0 个答案:

没有答案