首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在注入EntityManager 10 EJB时,WildFly为空

在注入EntityManager 10 EJB时,WildFly为空
EN

Stack Overflow用户
提问于 2017-09-08 20:38:38
回答 1查看 589关注 0票数 0

我一直在努力将我们的应用程序从JBoss 6迁移到Wildfly 10,我一直坚持的主要问题是EntityManager没有被注入到EJB中。我已经研究了一段时间,并尝试了我发现的一切,但没有任何帮助。

我还没有一个简单的应用程序来重新创建这个问题,但是这里有一些细节和代码片段。

我们正在使用一个SAR文件进行部署。这是一个Spring框架应用程序。我们的第二级缓存暂时关闭。这是我需要解决的另一个问题。

persistence.xml:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
                http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
        version="1.0">
  <persistence-unit name="IpsDb" transaction-type="JTA">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <jta-data-source>java:jboss/datasources/HarmonyServerDS</jta-data-source>
    <jar-file>../harmonyserver-model.jar</jar-file>
    <properties>
      <!-- pessimistic lock timeout in milliseconds (Integer or String), this is a hint used by Hibernate but requires support by your underlying database. -->
      <property name="javax.persistence.lock.timeout" value="15000"/>
      <!-- query timeout in milliseconds (Integer or String), this is a hint used by Hibernate but requires support by your underlying database --> 
      <property name="javax.persistence.query.timeout" value="15000"/>
      <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform" />
      <property name="hibernate.cache.use_query_cache" value="false"/>
      <property name="hibernate.cache.use_second_level_cache" value="false"/>
    </properties>
  </persistence-unit>
</persistence>

数据源从独立的-Ful.xml开始:

代码语言:javascript
复制
<datasource jta="true" jndi-name="java:jboss/datasources/HarmonyServerDS" pool-name="HarmonyServerDS" enabled="true" use-java-context="true" spy="false" use-ccm="true" connectable="false">

来自EJB类(这些是类中的重要部分,但不是所有代码):

代码语言:javascript
复制
@Stateless
@Clustered
public class DataModificationBean implements DataModificationLocal {

    @PersistenceUnit(unitName="IpsDb")
    private EntityManagerFactory entityMgrFactory;

    @PersistenceContext(unitName="IpsDb")
    private EntityManager entityMgr;

    @Override
    @Transactional(propagation=Propagation.REQUIRES_NEW)
    @InterruptOnTransactionTimeout(value=true)
    public DataModificationResponse handleModification(DataModification mod, ModificationHandler handler, AdaptationContext adaptation, boolean bulk_lock)
    {
        try {
            // Handler's data update monitor for delta changes. 
            DataUpdateMonitor updateMonitor = null;

            // Pre-process the request and gather up the dataContext for processing.
            logger.info("DataModificationBean EntityMgr=" + (entityMgr == null ? "null" : entityMgr.toString()));
            logger.info("DataModificationBean EntityMgrFactory=" + (entityMgrFactory == null ? "null" : entityMgrFactory.toString()));
            handler.preProcess(this, entityMgr);
...

代码段底部的日志记录显示entityMgr和entityMgrFactory为null。

还有什么东西我遗漏了吗?或者其他我能给你看的有用的东西?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-12 16:25:47

我发现了问题。我不得不将JNDI名称从我猜的旧格式更改为新格式。我换了一些,但不是这个豆子的。bean不是从上下文中找到的,因此在代码中创建了一个新bean。我们只有测试用例才有这段代码,但我没有注意到这就是它所做的。现在我已经修复了JNDI名称,找到了bean并注入了EntityMgr。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46124214

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档