【发布时间】:2021-07-01 05:47:25
【问题描述】:
我的代码如下: 实体
@Entity(name = "TerpCrtV")
@NamedQueries({
@NamedQuery(name = "deleteAllCrt", query = "DELETE FROM TerpCrtV")
})
命名查询在 DAO 层中调用如下:
@PersistenceContext(unitName="masterPU")
private EntityManager entityManagerMaster;
public int deleteAllCustomerTeams() throws Exception {
return entityManagerMaster.createNamedQuery("deleteAllCrt", TerpCrtV.class).executeUpdate();
}
使用 usertransaction 调用如下: 用户事务是 EJB 之一并注入到 bean 中
private void persist(List<TerpCrtV> terpCustomerTeams) throws Exception {
logger.info("In CustomerTeamsCopierImpl: Delete all CRT");
userTransaction.begin();
deleteAllCrtV();
userTransaction.commit();
我面临的错误如下:
2021-04-05 12:36:53,454 ERROR [org.jboss.as.ejb3.invocation] (EJB default - 2) WFLYEJB0034: EJB Invocation failed on component MasterdataPersistence for method public int com.evry.integrator.crm.persistence.MasterdataPersistence.deleteAllCustomerTeams() throws java.lang.Exception: javax.ejb.EJBTransactionRolledbackException: Update/delete queries cannot be typed
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:203)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:364)
]com.evry.integrator.crm.persistence.MasterdataPersistence$$$view7.deleteAllCustomerTeams(Unknown Source)
at com.evry.integrator.terpcrm.schedular.CustomerTeamsCopierImpl.deleteAllCrtV(CustomerTeamsCopierImpl.java:86)
at com.evry.integrator.terpcrm.schedular.CustomerTeamsCopierImpl.persist(CustomerTeamsCopierImpl.java:64)
at com.evry.integrator.terpcrm.schedular.CustomerTeamsCopierImpl.importDataFromTerpAndInsertToMasterdata(CustomerTeamsCopierImpl.java:139)
【问题讨论】:
标签: jpa ejb named-query