比方说我们有这样的实体(跳过吸气剂/设置剂,可见性参数,注释等)
class TargetEntity {
Integer id;
List <Attribute> attributes;// one to many
}
class Attribute {
Integer id;
AttributeType type;//many to one
String value;
}
class AttributeType{
Integer id;
String code;
String description;
}
我想同时选择所有不同的TargetEntities(通过和):
并按属性值对它们进行排序,其中属性代码等于Z(不存在该属性应视为空值)。
为此,我必须使用JPA标准API,并且无法向数据库添加任何视图。
谁能解释这种与标准API的透视相关的使用?
UPD:进行类似选择的sql查询大致如下:
select tet.* from target_entity_table tet
left join (
select attr.target_entity_table_id as hid, attr_type.code as code, attr.attribute_value as value from attribute_table attr
inner join attribute_type_table attr_type on attr.attribute_id = attr_type.id
) X on X.hid = tet.id and X.code = 'X'
left join (
select attr.target_entity_table_id as hid, attr_type.code as code, attr.attribute_value as value from attribute_table attr
inner join attribute_type_table attr_type on attr.attribute_id = attr_type.id
) Y on Y.hid = tet.id and Y.code = 'Y'
left join (
select attr.target_entity_table_id as hid, attr_type.code as code, attr.attribute_value as value from attribute_table attr
inner join attribute_type_table attr_type on attr.attribute_id = attr_type.id
) Z on Z.hid = tet.id and Z.code = 'Z'
where x.value = 'A' and Y.value != 'B'
order by z.value asc