JPA QL“IN”集合不适用于 openjpa 1.2.2
JPA 1 与 OpenJPA 1.2.2 位于单元测试支持的 Hsqldb 1.8 中。以下 JPA QL 不适用于 ids 列表上的“IN”。
@Transactional
public void updateSettlementId(List<Long> voucherIds, Long settlementId) {
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:在语句中找不到表 [UPDATE VOUCHER_PROCESSED t0 SET t1.settlement_id = ? WHERE (t0.voucher_id IN (?))]
VOUCHER_PROCESSED 表在运行测试时在 hsqldb 中创建,因此上述错误似乎是错误且具有误导性的。
建议?
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) {
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
适用于 Hibernate,但是(如果我错了,请纠正我)JPA 规范不允许
define允许在IN
构造setParameter()< 中使用集合/code> 对于像“
IN (:voucherIds)
”这样的查询,它是特定于供应商的。Try this:
works with Hibernate, but (please correct me if I'm wrong) JPA specification does not
defineallow using collection inIN
constructsetParameter()
for queries like "IN (:voucherIds)
", it is vendor specific.