Estou tendo um caso em que me inscrevi na mesa.
queryFactory
.select (queryBase.getColumns ())
.from (entityPath)
.leftJoin (QTodoEntity.todoEntity.parentLocation, QTodoEntity.todoEntity)
.leftJoin (QTodoEntity.locationEntity.country, QCountryEntity.countryEntity)
.where (queryBase.getFilters ())
.orderBy (queryBase.getOrderBy ())
.offset (queryBase.getOffset ())
.limit (queryBase.getLimit ())
.buscar()
.Stream()
.map (queryBase :: mapRow)
.collect (Collectors.toList ());
O alias do QTodoEntity criado na junção à esquerda é usado em todos os lugares da consulta. Embora deva usar o alias que foi criado na seleção de.
Consulta parece
selecione todo1.id, todo1.name, todo1.custom, todo1.selfChild de Todo todoOnSelect left outer join Todo todo1 em todoOnSelect.selfChild = todo1.id
mas a consulta deve ser -
selecione todoOnSelect.id, todoOnSelect.name, todoOnSelect.custom, todoOnSelect.selfChild de Todo todoOnSelect left outer join Todo todo1 em todoOnSelect.selfChild = todo1.id
Este não é um bug.
Este não é um bug.
Como você resolveu isso? Estou tendo o mesmo problema, a cláusula where está usando o alias 'left join', em vez do alias 'from', e os resultados estão incorretos.
Estou entendendo:
select count(sub.id) from category c
left join category sub on c.id = sub.id
where sub.type='A'
Deveria ser:
select count(c.id) from category c
left join category sub on c.id = sub.id
where c.type='A'
Aqui está o queryDsl:
QCategory category = QCategory.category;
query.from(category)
.leftJoin(category.subcategory, QCategory.category)
.where(category.type.equalsIgnoreCase("A"))
.fetchCount();
Obrigado
Tente algo assim -
Categoria QCategory = QCategory.category;
QCategory subCategory = nova QCategory ("sub");
query.from (categoria)
.leftJoin (categoria.subcategoria, subcategoria)
.where (category.type.equalsIgnoreCase ("A"))
.fetchCount ();
Isso dará um alias para a subCategoria e na cláusula where escolherá a entidade principal, não a unida à esquerda.
Tente algo assim -
Categoria QCategory = QCategory.category;
QCategory subCategory = nova QCategory ("sub");
query.from (categoria)
.leftJoin (categoria.subcategoria, subcategoria)
.where (category.type.equalsIgnoreCase ("A"))
.fetchCount ();Isso dará um alias para a subCategoria e na cláusula where escolherá a entidade principal, não a unida à esquerda.
Não sei por que funciona, mas com certeza funcionou.
Muito obrigado!
:)
Comentários muito úteis
Tente algo assim -
Categoria QCategory = QCategory.category;
QCategory subCategory = nova QCategory ("sub");
query.from (categoria)
.leftJoin (categoria.subcategoria, subcategoria)
.where (category.type.equalsIgnoreCase ("A"))
.fetchCount ();
Isso dará um alias para a subCategoria e na cláusula where escolherá a entidade principal, não a unida à esquerda.