简体   繁体   English

是否提供`EntityManagerFactory` 解决`Unable to retrieve EntityManagerFactory for unitName xyz`

[英]Would providing `EntityManagerFactory` solve `Unable to retrieve EntityManagerFactory for unitName xyz`

This is the (bottom) error from the stack trace:这是堆栈跟踪中的(底部)错误:

Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName null
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:138)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:171)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createQuery(EntityManagerWrapper.java:477)
...

The code is as follows (inspired by a @BalusC 's example I found on SO today):代码如下(灵感来自我今天在 SO 上找到的@BalusC示例):

@Stateless
public class GradService {

    @PersistenceContext
    private EntityManager em;

    public List<Grad> listAll() {
        return em.createQuery("SELECT g FROM Grad g", Grad.class).getResultList();
    }
}

As reference, this is my persistence.xml (webmodule-root:Configuration files:作为参考,这是我的persistence.xml(webmodule-root:配置文件: WEB-INF网络信息META-INF:persistence.xml META-INF: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="MojaPU" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>jdbc/ekstraResource</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
        </properties>
    </persistence-unit>
</persistence>

It seems, that you placed your persistence.xml file in wrong location.看来,您将persistence.xml 文件放在了错误的位置。 It should by located in /META-INF/ folder and not in WEB-INF.它应该位于 /META-INF/ 文件夹中,而不是位于 WEB-INF 中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法检索unitName的EntityManagerFactory - Unable to retrieve EntityManagerFactory for unitName 无法检索EntityManagerFactory的unitName null - Unable to retrieve EntityManagerFactory for unitName null 实体Bean:无法为unitName null检索EntityManagerFactory - Entity Beans : Unable to retrieve EntityManagerFactory for unitName null IllegalStateException无法为unitName检索EntityManagerFactory null - IllegalStateException Unable to retrieve EntityManagerFactory for unitName null java.lang.IllegalStateException:无法检索unitName CrudPU的EntityManagerFactory - java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName CrudPU 无法修复java.lang.IllegalStateException:无法检索unitName的EntityManagerFactory - Unable to fix java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName java.lang.IllegalStateException:无法使用Arquillian检索unitName Horizo​​nPU的EntityManagerFactory - java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName HorizonPU with Arquillian java.lang.IllegalStateException:无法为unitName null检索EntityManagerFactory - java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName null java.lang.illegalstateexception无法检索单位名称为null的entitymanagerfactory - java.lang.illegalstateexception unable to retrieve entitymanagerfactory for unitname null Java EE(打开)JPA-无法检索EntityManagerFactory - Java EE (Open)JPA - Unable to retrieve EntityManagerFactory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM