[請益] Spring-data-jpa的find IN query
請問各位大大有沒有遇過這樣的情況呢?
我有一個spring web app的專案,是採用spring-data-jpa跟openjpa
當作persistence。資料庫是PostgreSQL 9.4 Windows version。
專案內有大量使用spring-data-jpa的repository query method。
也就是可以直接宣告一個interface為findByIdIn即可達成
select * from device where id in (xxx,xxx,xxx)的效果。
public interface DeviceDao extends DaoFacade<Device, String>
{
List<Device> findByIdIn(Collection<String> deviceIdList);
}
這不需要任何的customized implementation就可以有作用,
spring-data-jpa會幫轉成SQL。其中DaoBase是:
@NoRepositoryBean
public interface DaoFacade<T extends EntityBase, ID extends Serializable>
extends JpaRepository<T, ID>, JpaSpecificationExecutor<T>
{}
本來這都跑得好好的,可是在我把openjpa升版之後就出問題了。
每一次都會撈到一樣的result
原本相關lib版本如下,jdk是1.8:
<springVersion>4.3.0.RELEASE</springVersion>
<springDataJpaVersion>1.10.2.RELEASE</springDataJpaVersion>
<openjpaVersion>2.2.2</openjpaVersion>
<postgreSQLJDBCVersion>9.4.1208</postgreSQLJDBCVersion>
一旦把 <openjpaVersion> 升到2.3.0或最新的2.4.1都會出現問題。
每次都撈到第一次的Device。簡單測試程式碼如下:
List<Device> devices = this.deviceDao.findByIdIn(Arrays.asList(new String[]{"1002"}));
System.out.println("1" + devices.getId());
List<Device> devices1 = this.deviceDao.findByIdIn(Arrays.asList(new String[]{"1003"}));
System.out.println("2" + devices1.getId());
2.2.2版下,devices會是1002而devices1會是1003沒有問題。
但2.3.0或2.4.1版本下兩次result都是1002。他問題出在每次
他都給1002這個參數下去query,而不是第二次就給1003。但
我已經關掉所有的Cache設定了。
唯一的不同點就只有openjpa的版本不一樣而已,也只有In會
出錯。像findByIdIs就不會。
不知道有沒有大大有遇過這樣的問題,有可能是我哪裡沒有設定好嗎?
感謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.194.224.251
※ 文章網址: https://www.ptt.cc/bbs/Soft_Job/M.1469526867.A.5DB.html
※ 編輯: Sanbeishuu (123.194.224.251), 07/26/2016 20:43:17
※ 編輯: Sanbeishuu (123.194.224.251), 07/26/2016 20:43:34
推
07/26 21:52, , 1F
07/26 21:52, 1F
→
07/26 22:33, , 2F
07/26 22:33, 2F
→
07/26 22:33, , 3F
07/26 22:33, 3F
→
07/26 22:34, , 4F
07/26 22:34, 4F
推
07/28 21:32, , 5F
07/28 21:32, 5F
→
07/28 21:32, , 6F
07/28 21:32, 6F
推
07/29 01:21, , 7F
07/29 01:21, 7F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
Soft_Job 近期熱門文章
41
133
PTT職涯區 即時熱門文章