如何不清除JPA缓存?
如何不清除JPA缓存?
代码搜索目的地,POI2DICON,POI3DICON,带有FindbyCode和FindbyName的目标类别。
但是,当在for语句中执行相同的参数(FindbyCode(“ A”))时,Select语句将在存储库中执行。
我知道在JPA的缓存中存在与FindbyCode(“ A”)相对应的值。
然后,在for语句中,findbyCode(“ a”)的查询应仅执行一次,但实际上,搜索了许多查询。
我想知道如何将FindbyCode(“ A”)的值保持在缓存中,以及为什么现在在代码中丢失FindbyCode(“ A”)的内容。
List<Destination> result = new ArrayList<>();
int headerLength = rows.get(0).size();
for (int i = 1; i < rows. size(); i++) {
Map<String, String> destinationMap = new HashMap<>();
makeDestinaionMap(destinationMap)
Destination findDestination = destinationRepository.findByCode(destinationMap.get("Identification Code"));
Poi2dIcon poi2dIcon = poi2dIconService.findByName(destinationMap.get("2DIcon")).get(0);
Poi3dIcon poi3dIcon = poi3dIconService.findByName(destinationMap.get("3DIcon")).get(0);
DestinationCategory destinationCategory = destinationCategoryService.findByName(destinationMap.get("Category")).get(0);
// builder -> save
Destination destination = Destination.builder()
...build()
if (findDestination != null) {
destination.setId(findDestination.getId());
}
result.add(destination);
}
destinationRepository.saveAll(result);
此致
How not to clear the JPA cache?
Code do Searching destination, poi2dicon, poi3dicon, destinationcategory with findByCode and findByName.
However, when executing the same parameter (findByCode("A")) in the for statement, the select statement is executed in the repository.
I know that the value corresponding to findByCode("A") exists in the cache of JPA.
Then, in the for statement, the query of findByCode("A") should be executed only once, but in reality, as many queries as rows.size are searched.
I wonder how to keep the value of findByCode("A") in the cache, and why the content of findByCode("A") is lost in the code now.
List<Destination> result = new ArrayList<>();
int headerLength = rows.get(0).size();
for (int i = 1; i < rows. size(); i++) {
Map<String, String> destinationMap = new HashMap<>();
makeDestinaionMap(destinationMap)
Destination findDestination = destinationRepository.findByCode(destinationMap.get("Identification Code"));
Poi2dIcon poi2dIcon = poi2dIconService.findByName(destinationMap.get("2DIcon")).get(0);
Poi3dIcon poi3dIcon = poi3dIconService.findByName(destinationMap.get("3DIcon")).get(0);
DestinationCategory destinationCategory = destinationCategoryService.findByName(destinationMap.get("Category")).get(0);
// builder -> save
Destination destination = Destination.builder()
...build()
if (findDestination != null) {
destination.setId(findDestination.getId());
}
result.add(destination);
}
destinationRepository.saveAll(result);
Best Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论