我有一个插入JPA命名查询,如下所示。当我尝试使用enity manger从我的DAO执行它时,我收到以下错误。我正在使用Apache OpenJPA,我无法确定此问题的根本原因。由于我的域对象的复杂性,我无法使用persist方法。
遇到" INSERT"在角色1,但预期:[" DELETE"," SELECT"," UPDATE"]。
@NamedQuery(
name=IuaPersistenceConstants.QUERY_INSERT_AGREEMENT_ACKNOWLEDGEMENT,
query="INSERT INTO AgreementAcknowledgement agrackn VALUES agrackn.id.agrmntCntntUrl = :agrmntCntntUrl, agrackn.id.prvsndUserSqn = :prvsndUserSqn, agrackn.id.prvsnUserEffD = :userEffDate, " +
"agrackn.id.agrmntacknEffD = :agrmntacknEffD, agrackn.acknExpD = :acknExpD, agrackn.crtTs = :crtTs, agrackn.crtUidC = :crtUidC, agrackn.lstUpdtTs = :lstUpdtTs, agrackn.lstUpdtUidC = :lstUpdtUidC")
Query ackQuery =getEntityManager().createNamedQuery(IuaPersistenceConstants.QUERY_INSERT_AGREEMENT_ACKNOWLEDGEMENT);
ackQuery.setParameter("agrmntCntntUrl", agreementDO.getAgreementURL());
ackQuery.setParameter("agrmntacknEffD", agreementDO.getAgreementEffDate());
ackQuery.setParameter("acknExpD", agreementDO.getAgreementExpDate());
ackQuery.setParameter("prvsndUserSqn", userDO.getUserSequence());
ackQuery.setParameter("userEffDate", userDO.getUserEffDate());
ackQuery.setParameter("crtTs", new Date());
ackQuery.setParameter("crtUidC", "WS");
ackQuery.setParameter("lstUpdtTs", new Date());
ackQuery.setParameter("lstUpdtUidC", "WS");
ackQuery.executeUpdate();
答案 0 :(得分:2)
OpenJPA doesn't seem to support JPQL "INSERT" queries。但是,这并不奇怪,因为JPA没有定义INSERT查询。它定义了SELECT,UPDATE,DELETE查询,这就是全部。参见JPA规范。这不是SQL。