Glassfish EJB 3 OpenJPA 2
由于这个问题,我现在进退两难。如果我将持久性上下文定义为:Glassfish EJB 3 OpenJPA 2,jpa,glassfish,ejb-3.0,Jpa,Glassfish,Ejb 3.0,由于这个问题,我现在进退两难。如果我将持久性上下文定义为: @PersistenceContext(unitName = "persistentUnit") private EntityManager entityManager; Glassfish拒绝以以下错误开始: SEVERE: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [com.ckd.business.
@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。但不管我做什么,玻璃鱼总是失败。我使用的是GlassFish3.1开源版
有人知道这方面的解决方案或解决方法吗?谢谢。这不是一个解决方案,而是一些想法: 我认为第一个是正确的用法。unitName必须与persistence.xml中的相同。应该有这样的东西
<persistence-unit name="persistentUnit">
...
</persistence-unit>
正如在的答案中所看到的,记住注入发生在构造函数之后
希望这有助于进一步了解。谢谢您的评论,但我已经在persistence.xml文件中指定了name=persistentUnit。最后,我不得不从硬盘上删除Glassfish服务器,重新下载并重新启动。它现在似乎起作用了。我很困惑,为什么Glassfish没有报告它不工作——即使是日志文件中的一行也会有帮助——但什么都没有。啊,太令人沮丧了。