如何不清除JPA缓存?

发布于 2025-02-02 18:05:49 字数 1523 浏览 0 评论 0原文

如何不清除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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文