0

I'm using hibernate 5.3.14 with hazelcast 3.11.5 as L2 cache provider and spring boot 2.1.11.

I have 3 entities defined with relations:

  • one order has many order items
  • one order has many custom fields L2 cache is enabled for entities, associations and queries.
@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 {

I have one repository:

@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();

There are 3 problems:

  1. repo method findById doesn't load from the cache the main entity, order, with the relation, customFields, indicated by entity graph loaded

  2. cached query results for repo method findAllActiveWithOrderItems does not seem to have the relations, orderItems, loaded by the FETCH JOIN

  3. cached query results for repo method findAllActiveWithOrderItems does not seem to have the relations loaded by the the EntityGraph, customFields

Are there any known hibernate tickets or workarounds to fix those?

DuDa
  • 3,718
  • 4
  • 16
  • 36
Ionut B
  • 3
  • 2

1 Answers1

0

That's a known issue and I think Hibernate 6.0 will fix it, but I don't remember if there ever was a ticket for this.

Christian Beikov
  • 15,141
  • 2
  • 32
  • 58
  • Thanks. I found the hibernate ticket for the 1th and 3rd problem https://hibernate.atlassian.net/browse/HHH-10179. But the second problem about honoring the LEFT JOIN FETCH on cached queries I still have no clue. – Ionut B Jan 13 '21 at 15:27
  • Also for caching the results of a FETCH JOIN query there is a hibernate bug opened: https://hibernate.atlassian.net/browse/HHH-2003 – Ionut B Jan 22 '21 at 13:02