尝试使用 executeUpdate() 插入/更新/删除时引发异常。选择查询工作正常。我已经尝试了堆栈溢出中提到的先前类似错误的所有建议。感谢任何指导。
环境:Websphere Liberty:17.0.0.2,Eclipselink 2.6.4,JPA 2.1
Liberty 服务器上启用的功能
<featureManager>
<feature>adminCenter-1.0</feature>
<feature>beanValidation-1.1</feature>
<feature>cdi-1.2</feature>
<feature>concurrent-1.0</feature>
<feature>ejbLite-3.2</feature>
<feature>el-3.0</feature>
<feature>jsf-2.2</feature>
<feature>jsp-2.3</feature>
<feature>localConnector-1.0</feature>
<feature>servlet-3.1</feature>
<feature>jpa-2.1</feature>
<!--The following features are available in Liberty base and above. -->
<feature>jaxb-2.2</feature>
</featureManager>
持久性.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="BlueeCron" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/BlueeUPMDataSource</jta-data-source>
<mapping-file>META-INF/queries.xml</mapping-file>
<class>com.bcbsnc.providers.models.BlueEReqst</class>
<class>com.bcbsnc.providers.models.BlueERespn</class>
<properties>
<property name="eclipselink.logging.level" value="ALL" />
<property name="eclipselink.logging.level.sql" value="FINE" />
<property name="eclipselink.logging.parameters" value="true" />
</properties>
</persistence-unit>
@Stateless
@Repository("emJPADao")
public class JPADao {
EntityManager entityManager = Persistence.createEntityManagerFactory("BlueeCron").createEntityManager();
public Integer purgeBxTables() {
Integer rowsDeleted = 0;
try {
Integer noOfDays = Integer.parseInt(this.getConfigurationData("PurgeBXTablesPeriod"));
rowsDeleted = entityManager.createNamedQuery("PURGE_BX_TABLES").setParameter("noOfDays", getTimeStamp(noOfDays, false)).executeUpdate();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(entityManager.isOpen())
entityManager.close();
}
} }
服务器启动时的日志 在
IBM J9 VM 版本 pwa6480sr4fp5-20170421_01 (SR4 FP5) 上启动 defaultServer (WebSphere Application Server 17.0.0.2/wlp-1.0.17.cl170220170523-1818) (en_US)
[AUDIT ] CWWKF0012I:服务器安装了以下功能:[jsp-2.3、ejbLite-3.2、servlet-3.1、jsf-2.2、beanValidation-1.1、ssl-1.0、jndi-1.0、jca-1.7、jdbc-4.2、localConnector -1.0、appSecurity-2.0、jaxrs-2.0、restConnector-1.0、el-3.0、jaxrsClient-2.0、concurrent-1.0、wmqJmsClient-2.0、jaxb-2.2、json-1.0、jpaContainer-2.1、adminCenter-1.0、cdi-1.2 ,分布式地图-1.0,jpa-2.1]。
[AUDIT ] CWWKF0011I: 服务器 defaultServer 已准备好运行更智能的星球。
[EL Info]:服务器:2017-10-19 10:23:13.215--ServerSession(1864654006)--检测到的服务器平台:org.eclipse.persistence.platform.server.was.WebSphere_Liberty_Platform。小号
异常:
[err] javax.persistence.TransactionRequiredException:异常描述:此线程当前没有活动的外部管理事务
[错误] 在 org.eclipse.persistence.internal.jpa.transaction.JTATransactionWrapper.throwCheckTransactionFailedException(JTATransactionWrapper.java:94)
[错误] 在 org.eclipse.persistence.internal.jpa.transaction.JTATransactionWrapper.checkForTransaction(JTATransactionWrapper.java:54)
[错误] 在 org.eclipse.persistence.internal.jpa.EntityManagerImpl.checkForTransaction(EntityManagerImpl.java:2054)
[错误] 在 org.eclipse.persistence.internal.jpa.QueryImpl.executeUpdate(QueryImpl.java:291)
[错误] 在 com.bcbsnc.providers.dao.JPADao.purgeBxTables(JPADao.java:49)