2011-03-21 112 views
0

我被卡在岩石和困难的地方之间此刻此刻的问题。如果我定义我的持久化上下文为:Glassfish EJB 3 OpenJPA 2

@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. 

但是,如果我改变了声明:

[email protected](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 OpenSource Edition

有没有人知道这个解决方案或解决方法?谢谢。

回答

0

不是一个解决办法,但一些想法:

我认为首先是正确的用法。 unitName必须与您的persistence.xml中的相同。应该有这样的事情

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

可以看出在回答this question,记得构造之后注入发生。

希望这有助于进一步了解。

+0

感谢您的评论,但我已经在** persistence.xml **文件中指定了** name =“persistentUnit”**。最后,我不得不从硬盘驱动器中删除Glassfish服务器,重新下载并重新开始。它现在似乎工作。尽管为什么Glassfish没有报告说它没有工作 - 即使日志文件中的一行可能会有帮助 - 我什么都没有。阿尔格,这太令人沮丧了。 – ChuongPham 2011-03-23 14:55:27