0

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-INF\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.

ChuongPham
  • 4,761
  • 8
  • 43
  • 53

1 Answers1

0

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.

Community
  • 1
  • 1
Matt Handy
  • 29,855
  • 2
  • 89
  • 112
  • Thanks for your comment but I already have **name="persistentUnit"** specified in the **persistence.xml** file. Eventually, I had to remove Glassfish server from the hard drive, re-download it and start again. It seems to work now. I'm stumped though why Glassfish did not report that it's not working - even a line in the log file would have helped - but nothing. Arrg, it was so frustrating. – ChuongPham Mar 23 '11 at 14:55