开发者

Glassfish EJB 3 OpenJPA 2

I'm stuck between a rock and a hard place at the moment with this problem. If I define my persistence context as:

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

Glassfish refused to start with the error:

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.

But if I changed the declaration to:

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

Glassfish is able to deploy my WAR file but when I load the page up I get this:

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

What the heck?! I have saved the persistence.xml file to WEB-IN开发者_JAVA技巧F\classes\META-INF directory as per the requirement and saw that Glassfish has loaded JPA properly. But it doesn't matter what I do, Glassfish always fail. I'm using Glassfish 3.1 OpenSource Edition.

Does anyone know of a solution or a workaround for this? Thanks.


Not a solution, but some thoughts:

I think the first is the correct usage. The unitName must be the same as in your persistence.xml. There should be something like this

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

As seen in the answer to this question, remember that injection takes place after the constructor.

Hope this helps to get a bit further.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜