Мне нужна помощь с фильтрацией root сущностей по дочерним сущностям ...
У меня есть эта модель (упрощенная), созданная с использованием данных пружины jpa:
Первичная - root сущность:
@Entity
@Table(name = "T_PRI_IMPL")
public class PricelistImplementation {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinTable(name = "T_PRI_IMPL_ATTR_REL_IMPL",
joinColumns = {
@JoinColumn(name = "FK_IMPL_ID", referencedColumnName = "ID",
nullable = false, updatable = false)},
inverseJoinColumns = {
@JoinColumn(name = "FK_ATTR_ID", referencedColumnName = "ID",
nullable = false, updatable = false)})
private List<PricelistImplementationAttribute> attributes;
...
}
И подэлемент атрибутов для прайс-листов ...
@Entity
@Table(name = "T_PRI_IMPL_ATTRIBUTE")
public class PricelistImplementationAttribute {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToMany(mappedBy = "attributes", fetch = FetchType.LAZY)
private List<PricelistImplementation> pricelistImplementations;
@Enumerated(EnumType.STRING)
private PricelistImplementationAttributeType type;
private String val;
}
Таким образом, один PricelistImplementation
может иметь несколько PricelistImplementationAttribute
атрибутов.
Примеры примеров:
1) PricelistImplementation
id # 1 имеют следующие атрибуты:
type=COMMODITY | value='water'
type=SYSTEM_ID | value='sale_pricelist_offer'
type=PUBLIC | value=true
type=DISTRIBUTOR | value=AnotherDistributor
2) PricelistImplementation
id # 2 имеют следующие атрибуты:
type=COMMODITY | value='gas'
type=SYSTEM_ID | value='standard_gas_pricelist'
type=PUBLIC | value=true
type=DISTRIBUTOR | value=FooDistributor
3) PricelistImplementation
id # 3 есть эти атрибуты:
type=COMMODITY | value='gas'
type=SYSTEM_ID | value='internal_gas_pricelist'
type=PUBLIC | value=false
type=DISTRIBUTOR | value=FooDistributor
4) PricelistImplementation
id # 4 имеет следующие атрибуты:
type=COMMODITY | value='water'
type=SYSTEM_ID | value='pricelist_for_companies'
type=PUBLIC | value=true
type=DISTRIBUTOR | value=AnotherDistributor
Поиск запросов примеров запросов
1) Найти все PricelistImplementation
реализации, имеющие attribute.type='COMMODITY' with attribute.value='gas'
и attribute.type='PUBLIC' with attribute.value=false
2 ) Найти все PricelistImplementation
реализации, имеющие attribute.type='COMMODITY' with attribute.value='water'
и attribute.type='DISTRIBUTOR' with attribute.value='AnotherDistributor'
Результаты поиска примеров вызовов
1) Должен вернуть PricelistImplementation
id 3
2) Должен вернуть PricelistImplementation
id 4 и 1
Суммировано: Как найти root объекты запросами к нескольким подобъектам с ключом / значением с CriteriaQuery
, пожалуйста?