I just closed this issue that you were referring to, as that was fixed in Hibernate 6. I don’t know what to tell you. Filtering a collection that you fetch is not safe, that’s why JPA doesn’t allow assigning an alias to a join fetch. In Hibernate 6, we fixed this unsafety. If you want to fetch a subset of data, what you need is a projection/DTO for which there are tools like e.g. Blaze-Persistence Entity-Views with which you can select exactly the data that you want. Your use case could be modeled with entity views like this:
@EntityView(CustomerOrder.class)
public interface CustomerOrderDto {
@IdMapping
Long getId();
@Mapping("orderPositionCollection[deleted = false]")
List<OrderPositionDto> getOrderPositionCollection();
}
@EntityView(OrderPosition.class)
public interface OrderPositionDto {
@IdMapping
Long getId();
Integer getAmount();
ProductDto getProduct();
}
@EntityView(Product.class)
public interface ProductDto {
@IdMapping
Long getId();
String getProductName();
}
|