开发者

JPA QL "IN" collection doesn't work for openjpa 1.2.2

开发者 https://www.devze.com 2023-03-04 01:25 出处:网络
JPA 1 with OpenJPA 1.2.2 in a unit-test backed Hsqldb 1.8. The following JPA QL doesn\'t work with a \"IN\" on a List of ids doesn\'t work.

JPA 1 with OpenJPA 1.2.2 in a unit-test backed Hsqldb 1.8. The following JPA QL doesn't work with a "IN" on a List of ids doesn't work.

@Transactional
public void updateSettlementId(List<Long> voucherIds, Long settlementId)开发者_StackOverflow社区 {
    String query = "UPDATE VoucherProcessed vp SET vp.settlement.id=:settlementId where vp.voucher.id IN (:voucherIds)";
    em.createQuery(query).setParameter("settlementId", settlementId)
            .setParameter("voucherIds", StringUtils.join(voucherIds.iterator(), ","))
            .executeUpdate();
}

java.sql.SQLException: Table not found in statement [UPDATE VOUCHER_PROCESSED t0 SET t1.settlement_id = ? WHERE (t0.voucher_id IN (?))]

VOUCHER_PROCESSED table is being created in hsqldb while the test is run so the above error seems erroneous and misleading.

Suggestions?


Try this:

  .setParameter("voucherIds", voucherIds)

works with Hibernate, but (please correct me if I'm wrong) JPA specification does not define IN construct allow using collection in setParameter() for queries like "IN (:voucherIds)", it is vendor specific.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号