[请益] Spring-data-jpa的find IN query

楼主: Sanbeishuu (三杯鼠)   2016-07-26 17:54:24
请问各位大大有没有遇过这样的情况呢?
我有一个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就不会。
不知道有没有大大有遇过这样的问题,有可能是我哪里没有设定好吗?
感谢
作者: conanist (QQ)   2016-07-26 21:52:00
你要不要去看一下openjpaVersion 2.41 的what's new?
楼主: Sanbeishuu (三杯鼠)   2016-07-26 22:33:00
C大 因为2.3.0以上就会发生这个现象所以我有去看了2.3.0, 2.4.0, 2.4.1的release note但是New或者bug fix没有看到有相关的说
作者: ljf0030 (小小工程师)   2016-07-28 21:32:00
抓得到source code 吗?不然反解释class 看最后产生的sql对不对 。
作者: jhjhs33504 ( )   2016-07-29 01:21:00
看起来新版没有再往this内的下一个对应的物件找

Links booklink

Contact Us: admin [ a t ] ucptt.com