【问题标题】:Glassfish EJB 3 OpenJPA 2Glassfish EJB 3 OpenJPA 2
【发布时间】:2011-03-21 07:34:02
【问题描述】:

由于这个问题,我现在陷入了困境。如果我将持久性上下文定义为:

@PersistenceContext(unitName = "persistentUnit")
private EntityManager entityManager;

Glassfish 拒绝启动错误:

SEVERE: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [com.ckd.business.MusicService/entityManager] in the scope of the module called [home]. Please verify your application.

但如果我将声明更改为:

e@PersistenceContext(name = "persistentUnit")
private EntityManager entityManager;

Glassfish 能够部署我的 WAR 文件,但是当我加载页面时,我得到了这个:

java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName null

什么鬼?!我已根据要求将 persistence.xml 文件保存到 WEB-INF\classes\META-INF 目录,并看到 Glassfish 已正确加载 JPA。但不管我做什么,Glassfish 总是失败。我正在使用 Glassfish 3.1 开源版

有人知道解决方案或解决方法吗?谢谢。

【问题讨论】:

    标签: jpa glassfish ejb-3.0


    【解决方案1】:

    不是解决方案,而是一些想法:

    我认为第一个是正确的用法。 unitName 必须与您的 persistence.xml 中的相同。应该有这样的

    <persistence-unit name="persistentUnit">
     ...
    </persistence-unit>
    

    正如this question 的回答中所见,请记住注入发生在构造函数之后。

    希望这有助于进一步发展。

    【讨论】:

    • 感谢您的评论,但我已经在 persistence.xml 文件中指定了 name="persistentUnit"。最后,我不得不从硬盘驱动器中删除 Glassfish 服务器,重新下载并重新开始。它现在似乎起作用了。我很困惑为什么 Glassfish 没有报告它不工作——即使是日志文件中的一行也会有所帮助——但没有任何帮助。 Arrg,这太令人沮丧了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-25
    • 2013-08-02
    • 1970-01-01
    相关资源
    最近更新 更多