簡體   English   中英

Hibernate EntityGraph 和 LEFT JOIN FETCH 查詢的二級緩存問題

[英]Hibernate L2 cache issues with EntityGraph and LEFT JOIN FETCH queries

我使用 hibernate 5.3.14 和 hazelcast 3.11.5 作為二級緩存提供程序和 spring 引導 2.1.11。

我有 3 個用關系定義的實體:

  • 一個訂單有多個訂單項
  • 一個訂單有很多自定義字段 為實體、關聯和查詢啟用二級緩存。
@Entity
@Table(name = "orders")
@org.hibernate.annotations.Cache(usage =CacheConcurrencyStrategy.READ_WRITE)
public class Order extends AbstractBaseEntity implements Orderable {

    @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @LazyCollection(LazyCollectionOption.TRUE)
    @Fetch(FetchMode.SELECT)
    private List<OrderItem> orderItems;

@MappedSuperclass
public abstract class AbstractBaseEntity

    @OneToMany(orphanRemoval = true, cascade = CascadeType.ALL)
    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @JoinColumn(name = "parent_rid")
    @LazyCollection(LazyCollectionOption.TRUE)
    private List<CustomField> customFields = new ArrayList<>();

@Entity
@Table(name = "custom_fields")
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class CustomField implements Serializable {

@Entity
@Table(name = "order_items")
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class OrderItem extends AbstractBaseEntity implements Orderable {

我有一個存儲庫:

@Repository
public interface OrderRepository extends JpaRepository<Order, String> {

    @EntityGraph(attributePaths = "customFields")
    Optional<Order> findById(String rid);

    @QueryHints(value = {@QueryHint(name = "org.hibernate.cacheable", value = "true")})
    @EntityGraph(attributePaths = "customFields")
    @Query("select o from Order left join fetch o.orderItems where o.status = 'ACTIVE' ")
    List<Order> findAllActiveWithOrderItems();

有3個問題:

  1. repo 方法findById不會從緩存中加載主要實體,順序,關系,customFields,由加載的實體圖指示

  2. repo 方法findAllActiveWithOrderItems的緩存查詢結果似乎沒有由 FETCH JOIN 加載的關系 orderItems

  3. repo 方法findAllActiveWithOrderItems的緩存查詢結果似乎沒有由 EntityGraph、customFields 加載的關系

是否有任何已知的 hibernate 票或解決方法來解決這些問題?

這是一個已知問題,我認為 Hibernate 6.0 會修復它,但我不記得是否有過此問題的票證。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM