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:
repo method
findById
doesn't load from the cache the main entity, order, with the relation, customFields, indicated by entity graph loadedcached query results for repo method
findAllActiveWithOrderItems
does not seem to have the relations, orderItems, loaded by the FETCH JOINcached 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?