Hibernate DISTINCT在JPA中使用的是哪一列?是否可以更改它?
JPQL中的Distinct最常用于在执行左外部联接时选择一个Distinct对象 此查询:Hibernate DISTINCT在JPA中使用的是哪一列?是否可以更改它?,hibernate,jpa,jpql,Hibernate,Jpa,Jpql,JPQL中的Distinct最常用于在执行左外部联接时选择一个Distinct对象 此查询: select distinct sirm.attribute from store_item_received_material sirm where sirm.store_item_id in (select si.id from store_item si where si.program_id = 9 and si.customer_id = 1 and si.date_processed is
select distinct sirm.attribute
from store_item_received_material sirm
where sirm.store_item_id in (select si.id from store_item si where si.program_id = 9 and si.customer_id = 1 and si.date_processed is not null);
将在地址集合中选择客户及其所有地址。如果您不在此处使用DISTINCT,则同一客户将为每个地址重复一次
您也可以使用DISTINCT选择列,但它将只返回该列:
SELECT DISTINCT c
FROM Customer c
LEFT JOIN FETCH c.addresses
这样,结果列表将是一个包含客户名称的字符串集合。JPQL中的Distinct最常用于在执行左外部联接时选择一个Distinct对象 此查询:
select distinct sirm.attribute
from store_item_received_material sirm
where sirm.store_item_id in (select si.id from store_item si where si.program_id = 9 and si.customer_id = 1 and si.date_processed is not null);
将在地址集合中选择客户及其所有地址。如果您不在此处使用DISTINCT,则同一客户将为每个地址重复一次
您也可以使用DISTINCT选择列,但它将只返回该列:
SELECT DISTINCT c
FROM Customer c
LEFT JOIN FETCH c.addresses
这样,结果列表将是一个包含客户名称的字符串集合。引用这一个,它可能会有帮助引用这一个,它可能会有帮助