tags:

views:

159

answers:

2

I have an app using Wicket for the presentation layer with CDI/Weld, JPA 2.0, EJB 3.1 etc. (JEE 6) deployed on GlassFish v3.0.1.

When I try to inject an EJB into a wicket page using @EJB I get the following error: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName

When I try to inject using @Inject, I get the following error: java.lang.IllegalStateException: Unable to convert ejbRef for ejb UserRepository to a business object of type class

I believe the problem is stemming from JPA. I am using the exact same configuration that I used with a JSF application which worked properly, so I am lost as to what the issue could be. The connection pools are set up properly and pinging correctly through GlassFish, I have included wicket-weld on the classpath and I have even tried using the old Java EE 5 wicketstuff project for wicketstuff-javaeeapi with the same results.

Any help would be appreciated.

Thanks.

A: 

Could always try to lookup the EJB via its standard "java:global" name. That should at least let you rule out wicket as a possible source of issues and get you a little closer to a working system.

David Blevins
Thanks for the suggestion, I already used jndi lookup to attempt to get the EJB and I got the same EMF error. I am running out of ideas.
kgrad
Sounds like an EJB/JPA issue and not at all related to Wicket. If you haven't, fill the 'unitName' and 'name' attributes; @PersistenceUnit(unitName="foo") should exactly match the persistence.xml/<persistence><persistence-unit name="foo"> -- Note, you can use default rules and not specify unitName, but this can quickly bite you if another persistence unit is added to the app or persistence.xml.
David Blevins
+1  A: 

If you get the exception:

Unable to retrieve EntityManagerFactory for unitName

It might mean it is not detecting your persistence.xml file. Make sure it's in the WEB-INF\classes\META-INF directory.

You can verify that your app has JPA enabled by going to the Admin Console in GlassFish, go to the Applications section and see if it shows something like [ejb, web, weld, jpa] for your app. If it doesn't show jpa then it's not finding your JPA config file.

cdmckay
You are my hero! Why is it different than the JSF config? Why isn't this documented better?
kgrad