我正在使用 JBoss AS 7.1.1 并且能够配置新的 JTA 数据源并将其连接到我的 EJB 使用
@PersistenceContext(unitName="TestPU")
private EntityManager entityManager;
当我尝试使用 RESOURCE_LOCAL PersistenceUnit 时,我收到错误消息,说我无法使用 @PersistenceContext 注入 RESOURCE_LOCAL PU。
我已将我的 persistence.xml 配置如下:
<persistence-unit name="TestPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/xy"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="blah"/>
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
在我的 DAO 中,
@Stateless
public class UserDAO {
@PersistenceContext(unitName="TestPU")
private EntityManager entityManager;
}
当我在 AS 7.1.1 上部署我的应用程序时,我收到以下错误。
JBAS011428: Cannot inject RESOURCE_LOCAL container managed EntityManagers using @PersistenceContext
at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor$1.handle(ModuleJndiBindingProcessor.java:169)
at org.jboss.as.ee.component.ClassDescriptionTraversal.run(ClassDescriptionTraversal.java:54)
at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.processClassConfigurations(ModuleJndiBindingProcessor.java:162)
at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.deploy(ModuleJndiBindingProcessor.java:155)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
... 5 more
将 RESOURCE_LOCAL PU 与 @PersistenceContext 一起使用的任何解决方案?