我有一个具有一些数据库操作的会话 bean 类。我需要将该类与多个数据库一起使用,因此我配置 ejb-jar.xml 以从该类创建会话 bean,每个 bean 用于每个数据库。这是代码。
public class UserEM
{
/** The entity manager */
@Resource(name="userEntityManager/em")
private EntityManager em;
public EntityManager getEntityManager()
{
return this.em;
}
... Database operations using the `em` ...
}
这是ejb-jar.xml
...
<enterprise-beans>
<session>
<ejb-name>UserEM1</ejb-name>
<ejb-class>com.abc.app.dao.UserEM</ejb-class>
<session-type>Stateless</session-type>
<persistence-context-ref>
<persistence-context-ref-name>userEntityManager/em</persistence-context-ref-name>
<persistence-unit-name>DataSource1</persistence-unit-name>
</persistence-context-ref>
</session>
<session>
<ejb-name>UserEM2</ejb-name>
<ejb-class>com.abc.app.dao.UserEM</ejb-class>
<session-type>Stateless</session-type>
<persistence-context-ref>
<persistence-context-ref-name>userEntityManager/em</persistence-context-ref-name>
<persistence-unit-name>DataSource1</persistence-unit-name>
</persistence-context-ref>
</session>
</enterprise-beans>
</ejb-jar>
...
当我只创建一个会话 bean 时,它按预期工作。但是我创建了两个以上,它在部署时引发异常:
Caused by: java.lang.IllegalArgumentException: JBAS011053: Incompatible conflicting binding at java:comp/env/userEntityManager/em source: org.jboss.as.jpa.injectors.PersistenceContextInjectionSource@937b07ef
at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.addJndiBinding(ModuleJndiBindingProcessor.java:237)
at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.deploy(ModuleJndiBindingProcessor.java:136)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
这里发生了什么。任何人都可以帮忙吗?任何建议或意见均被采纳。
名和