[英]EntityGraph or Join Fetch with Inheritance in JPA/Hibernate
[英]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個問題:
repo 方法findById
不會從緩存中加載主要實體,順序,關系,customFields,由加載的實體圖指示
repo 方法findAllActiveWithOrderItems
的緩存查詢結果似乎沒有由 FETCH JOIN 加載的關系 orderItems
repo 方法findAllActiveWithOrderItems
的緩存查詢結果似乎沒有由 EntityGraph、customFields 加載的關系
是否有任何已知的 hibernate 票或解決方法來解決這些問題?
這是一個已知問題,我認為 Hibernate 6.0 會修復它,但我不記得是否有過此問題的票證。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.