【发布时间】:2015-06-04 00:05:13
【问题描述】:
我正在尝试通过命名约定(不使用@Query)对 JPA 存储库进行删除。
关键是我有一个@EmbeddedId,所以repo header 看起来像
public interface MatchPronosticsRepository extends JpaRepository<MyClass, MyID>
所以默认情况下我有一个方法delete(MyID id),但我需要像delete(Iterable<? extends MyID>) 这样的东西,这样我就可以一枪杀死一些物体。关于如何解决它的任何想法?没找到
谢谢!
编辑
我尝试添加void deleteByMatchPronosticPk (Iterable<? extends MatchPronosticPK> ids);
但结果很奇怪。似乎在做一个 Select 会很好,但使用 3 个字段和 3 个值,但只有 2 个占位符:S
Hibernate:
select
matchprono0_.match_id as match3_4_,
matchprono0_.isprimary as isprimar1_4_,
matchprono0_.user_id as user4_4_,
matchprono0_.match_result as match2_4_
from
match_pronostics matchprono0_
where
(
matchprono0_.match_id, matchprono0_.isprimary, matchprono0_.user_id
)=(
? , ?
)
2015-06-03 21:41:18,149 TRACE: org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [1] as [BIGINT] - 58
2015-06-03 21:41:18,149 TRACE: org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [2] as [BOOLEAN] - true
2015-06-03 21:41:18,149 TRACE: org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [3] as [BIGINT] - 26
2015-06-03 21:41:18,149 WARN : org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 22023
2015-06-03 21:41:18,149 ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - The column index is out of range: 3, number of columns: 2.
暂时的解决方法
需要继续做一些其他的事情...由于删除是在尝试删除之前在内部执行选择,这不会比我试图实现的原始代码更损害性能
List<MatchPronostic> pronosticsToDelete = matchPronosticsRepository.findAll(ids);
matchPronosticsRepository.deleteInBatch(pronosticsToDelete);
【问题讨论】:
标签: java hibernate jpa repository