我一直在努力将我们的应用程序从JBoss 6迁移到Wildfly 10,我一直坚持的主要问题是EntityManager没有被注入到EJB中。我已经研究了一段时间,并尝试了我发现的一切,但没有任何帮助。
我还没有一个简单的应用程序来重新创建这个问题,但是这里有一些细节和代码片段。
我们正在使用一个SAR文件进行部署。这是一个Spring框架应用程序。我们的第二级缓存暂时关闭。这是我需要解决的另一个问题。
persistence.xml:
<?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开始:
<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类(这些是类中的重要部分,但不是所有代码):
@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。
还有什么东西我遗漏了吗?或者其他我能给你看的有用的东西?
发布于 2017-09-12 16:25:47
我发现了问题。我不得不将JNDI名称从我猜的旧格式更改为新格式。我换了一些,但不是这个豆子的。bean不是从上下文中找到的,因此在代码中创建了一个新bean。我们只有测试用例才有这段代码,但我没有注意到这就是它所做的。现在我已经修复了JNDI名称,找到了bean并注入了EntityMgr。
https://stackoverflow.com/questions/46124214
复制相似问题