看板 Soft_Job 關於我們 聯絡資訊
請問各位大大有沒有遇過這樣的情況呢? 我有一個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
conanist: 你要不要去看一下openjpaVersion 2.41 的what's new? 07/26 21:52
Sanbeishuu: C大 因為2.3.0以上就會發生這個現象 07/26 22:33
Sanbeishuu: 所以我有去看了2.3.0, 2.4.0, 2.4.1的release note 07/26 22:33
Sanbeishuu: 但是New或者bug fix沒有看到有相關的說 07/26 22:34
ljf0030: 抓得到source code 嗎?不然反解釋class 看最後產生的sql 07/28 21:32
ljf0030: 對不對 。 07/28 21:32
jhjhs33504: 看起來新版沒有再往this內的下一個對應的物件找 07/29 01:21