如何在Spring Data中部分使用Hazelcast?

huangapple go评论69阅读模式
英文:

How to partially use Hazelcast with Spring Data?

问题

我有一个相当复杂的应用程序,涉及数十个实体,其中一些以多层次层次结构相关联。

我正试图为其中一个实体 Post 引入 Hazelcast。也就是说,我使用 @KeySpace 对实例进行了注释,实现了 ComparableSerializable,并使其仓库 PostRepository 扩展了 KeyValueRepository,所有这些都如此视频 https://www.youtube.com/watch?v=r0qlIPXkb-4 中所解释的那样。

这个实体与其他几个实体有关联,例如它有一个属性 private List<PostComment> comments

现在,当我从 PostRepository 中获取一个帖子时,我注意到 Hibernate 会打印出用于获取它的查询,涉及到相关实体的多个连接,例如 select ... from post post0_ left outer join post_comment...。我假设 Hibernate 打印这些意味着它会访问数据库,而不是从 Hazelcast 中获取数据。

我的问题是,如何配置这些实体也由 Hazelcast 缓存?

英文:

I have a somehow complex application, with a dozen of entities, some of them related in a several-layer hierarchy.

I am trying to introduce Hazelcast for one of the entities, Post. That is, I annotated the instance with @KeySpace, implemented Comparable, Serializable and made its repository, PostRepository extend KeyValueRepository, all as explain in this video https://www.youtube.com/watch?v=r0qlIPXkb-4.

This entity has relations to several other entities, for instance it has a property private List<PostComment> comments.

Now, when I fetch a post from PostRepository, I notice that Hibernate keeps printing the query to fetch it, several joins for the related entities as select ... from post post0_ left outer join post_comment.... I am assuming that Hibernate printing this means that is going to DB and not fetching the data from Hazelcast.

My question is, how do I configure that these entities are also cached by Hazelcast?

答案1

得分: 1

我认为您还需要使用@KeySpace标记所有相关的实体。否则,它将始终需要直接从数据库中获取关系。

在这里有一个很好的代码示例,展示了如何在应用程序和数据库之间添加Hazelcast作为一层中间层。

换句话说,我认为您不能仅针对部分连接的实体使用Spring Data Hazelcast。

英文:

I think you'd also need to mark all related entities with @KeySpace. Otherwise it will always need to take the relationships directly from the database.

Here's a good Code Sample of adding Hazelcast as a layer in-between the application and database.

In other words, I don't think you can use Spring Data Hazelcast only for part of connected entities.

huangapple
  • 本文由 发表于 2020年3月16日 22:38:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/60707950.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定