JPA QL "IN" collection doesn't work for openjpa 1.2.2
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 allow using collection in IN
constructsetParameter()
for queries like "IN (:voucherIds)
", it is vendor specific.
精彩评论