当我第一次使用已发布的部署应用程序启动我的应用程序服务器时,任何注入在特定模块中声明的持久性单元的尝试都会在第一次调用声明它的 bean 时失败。我可以通过重新启动应用程序来解决这个问题,但是每次我重新发布时都会发生这种情况。
我正在使用 WebSphere v8.0.4.2 并通过 Rational Application Developer v8 进行开发(尽管我认为这无关紧要)。
注意:包含ABCBean
和EntityManager
位于 中ABC.jar
,而OTHERMODULE.jar
是与异常相关的代码。这些模块是一个 EAR 文件的一部分。
所以:
ABC
\__ ABCBean
\__ META-INF/persistence.xml
OTHERMODULE
\__ beans that call above bean and cannot resolve persistence unit.
调用持久性 bean 时遇到的异常是:
javax.ejb.EJBTransactionRolledbackException: nested exception is: javax.ejb.EJBException: The ABCBean/em reference of type javax.persistence.EntityManager for the ABCBean component in the XYZ.jar module of the MYAPP application cannot be resolved.
javax.ejb.EJBException: The ABCBean/em reference of type javax.persistence.EntityManager for the ABCBean component in the OTHERMODULE.jar module of the MYAPP application cannot be resolved.
at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectionObject(InjectionBinding.java:1100)
at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectableObject(InjectionBinding.java:1013)
at com.ibm.wsspi.injectionengine.InjectionTarget.inject(InjectionTarget.java:198)
at com.ibm.ws.injectionengine.AbstractInjectionEngine.inject(AbstractInjectionEngine.java:947)
at com.ibm.ejs.container.StatelessBeanO.initialize(StatelessBeanO.java:300)
at com.ibm.ejs.container.BeanOFactory.create(BeanOFactory.java:147)...
这是我的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" ...>
<persistence-unit name="ABC_EJB">
<jta-data-source>jdbc/***</jta-data-source>
...
</persistence-unit>
</persistence>
以及异常中的类:
@Stateless
@LocalBean
public class ABCBean {
...
@PersistenceContext(unitName = "ABC_EJB")
private EntityManager em;
...
}