简体   繁体   English

使用Wicket / JPA注入实体管理器时出错

[英]Error injecting entity manager with Wicket/JPA

I have an app using Wicket for the presentation layer with CDI/Weld, JPA 2.0, EJB 3.1 etc. (Java EE 6) deployed on GlassFish v3.0.1. 我有一个使用Wicket的应用程序用于表示层,并在GlassFish v3.0.1上部署了CDI / Weld,JPA 2.0,EJB 3.1等(Java EE 6)。

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 当我尝试使用@EJB将EJB注入到wicket页面中时,出现以下错误:java.lang.IllegalStateException:无法为unitName检索EntityManagerFactory

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 当我尝试使用@Inject进行注入时,出现以下错误:java.lang.IllegalStateException:无法将ejb UserRepository的ejbRef转换为类型类的业务对象

I believe the problem is stemming from JPA. 我认为问题出在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. 我使用的是与正常工作的JSF应用程序所使用的完全相同的配置,因此我对可能出现的问题感到迷惑。 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. 连接池已正确设置并通过GlassFish正确ping通,我在类路径中包括了wicket-weld,甚至尝试对wicketstuff-javaeeapi使用旧的Java EE 5 wicketstuff项目,其结果相同。

Any help would be appreciated. 任何帮助,将不胜感激。

If you get the exception: 如果出现异常:

Unable to retrieve EntityManagerFactory for unitName 无法检索unitName的EntityManagerFactory

It might mean it is not detecting your persistence.xml file. 这可能意味着它没有检测到您的persistence.xml文件。 Make sure it's in the WEB-INF\\classes\\META-INF directory. 确保它在WEB-INF\\classes\\META-INF目录中。

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. 通过转到GlassFish中的管理控制台,转到“应用程序”部分,查看应用程序是否显示类似[ejb, web, weld, jpa] ,可以验证您的应用程序已启用JPA。 If it doesn't show jpa then it's not finding your JPA config file. 如果未显示jpa则找不到您的JPA配置文件。

Could always try to lookup the EJB via its standard "java:global" name. 总是可以尝试通过其标准的“ java:global”名称来查找EJB。 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. 那至少应该让您排除检票口作为问题的可能根源,并使您更接近工作系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM