-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Group by with paginated criteria builder use case #194
Comments
I think that giving the possibility to define the id attribute by which the PaginatedCriteriaBuilder should paginate is enough. That would make custom groupings possible which entity views could directly make use of as they are requiring an I'd mapping anyway. |
I think I stumbled up on this issue too, can you confirm? CriteriaBuilder return scopeEntityManager.getRecursiveScopeChildrenCriteriaBuilder(scope, Tuple.class)
.from(Contract.class, "contract")
.joinDefault("contract.scopes", "contractScope", JoinType.INNER)
.where("contractScope.id").in().from(ScopeCte.class, "s").select("s.id").end()
.whereOr().where("contract.endDate").isNull().where("contract.endDate").gt(LocalDateTime.now()).endOr()
.select("contract.employee.id", "id")
.select("contract.employee.name", "name")
.select("contract.employee.surname", "surname")
.select("contract.employee.email", "email")
.select("contract.employee.mobilePhone", "mobilePhone")
.select("FUNCTION('GROUP_CONCAT', contract.function.name, 'SEPARATOR', ', ', 'ORDER BY', contract.function.name, 'ASC')", "functions")
.orderByAsc("contract.employee.surname").orderByAsc("contract.employee.name").orderByAsc("contract.employee.id")
.page(firstResult, maxResults)
.getResultList(); Error message
|
The message tells you already :) |
Actually, now that I know this limitation, I changed my Criteria expressions to: return scopeEntityManager.getRecursiveScopeChildrenCriteriaBuilder(scope, Tuple.class)
.from(Employee.class, "employee")
.joinDefault("employee.contracts", "contract", JoinType.INNER)
.joinDefault("contract.scopes", "contractScope", JoinType.INNER)
.where("contractScope.id").in().from(ScopeCte.class, "s").select("s.id").end()
.whereOr().where("contract.endDate").isNull().where("contract.endDate").gt(LocalDateTime.now()).endOr()
.select("employee.id", "id")
.select("employee.name", "name")
.select("employee.surname", "surname")
.select("employee.email", "email")
.select("employee.mobilePhone", "mobilePhone")
.select("FUNCTION('GROUP_CONCAT', contract.function.name, 'SEPARATOR', ', ', 'ORDER BY', contract.function.name, 'ASC')", "functions")
.orderByAsc("employee.surname").orderByAsc("employee.name").orderByAsc("employee.id")
.page(firstResult, maxResults)
.getResultList(); And it seems to pass my initial test. |
…nce handling when order by item is not nullable. Fixes Blazebit#418. Fixes Blazebit#569. Fixes Blazebit#194
…nce handling when order by item is not nullable. Fixes Blazebit#418. Fixes Blazebit#569. Fixes Blazebit#194
…nce handling when order by item is not nullable. Fixes Blazebit#418. Fixes Blazebit#569. Fixes Blazebit#194
…nce handling when order by item is not nullable. Fixes Blazebit#418. Fixes Blazebit#569. Fixes Blazebit#194
…nce handling when order by item is not nullable. Fixes Blazebit#418. Fixes Blazebit#569. Fixes Blazebit#194
…nce handling when order by item is not nullable. Fixes Blazebit#418. Fixes Blazebit#569. Fixes Blazebit#194
…nce handling when order by item is not nullable. Fixes Blazebit#418. Fixes Blazebit#569. Fixes Blazebit#194
…nce handling when order by item is not nullable. Fixes Blazebit#418. Fixes Blazebit#569. Fixes Blazebit#194
…nce handling when order by item is not nullable. Fixes Blazebit#418. Fixes Blazebit#569. Fixes Blazebit#194
…y null precedence handling when order by item is not nullable
…cit group by when expressions are equivalent to the minimal group by clause
…cit group by when expressions are equivalent to the minimal group by clause. Fix hashCode generation for primitive booleans in flat views
…p by when expressions are equivalent to the minimal group by clause. Fix hashCode generation for primitive booleans in flat views
The scenario where I would use this for is still not supported: CriteriaBuilder<Contract> resultsQuery = someBaseCriteriaBuilder
.orderByAsc("employeeContract.employee.name")
.orderByAsc("employeeContract.employee.surname")
.orderByAsc("employeeContract.employee.id")
.groupBy("employeeContract.employee.id");
EntityViewSetting<ContractBasedEmployeeView, PaginatedCriteriaBuilder<ContractBasedEmployeeView>> setting =
EntityViewSetting.create(ContractBasedEmployeeView.class, firstResult, maxResults);
return entityViewManager.applySetting(setting, resultsQuery)
.getResultList(); Fails with:
I'd assume uniqueness of the |
Simplified the query, omitted the Basically what I'm trying to achieve comes down to the following return getEmployeeContractsCriteriaBuilder(traverseUp, traverseDown, includeInactive, javax.persistence.Tuple.class)
.orderByAsc("employeeContract.employee.name")
.orderByAsc("employeeContract.employee.surname")
.orderByAsc("employeeContract.employee.id")
.groupBy("employeeContract.employee.id")
.select("employeeContract.employee.id", "id")
.select("employeeContract.employee.name", "name")
.select("employeeContract.employee.surname", "surname")
.select("CASE WHEN (FUNCTION('MAX_DATE_TIME_NON_NULL', employeeContract.endDate) < CURRENT_TIMESTAMP) THEN false ELSE true END", "active")
.select("FUNCTION('GROUP_CONCAT', 'DISTINCT', employeeContract.function.name, 'SEPARATOR', ', ')", "function")
.page(firstResult, maxResults)
.getResultList(); This fails however with another exception, one that leads me to believe we're not constructing the count clause properly:
|
My conclusion is that:
|
Today we had a use case for using a paginated criteria builder in combination with a group by.
Right now, we don't support that, since we need some group by transformations to make a paginated criteria builder possible.
Think about what we can do to make this use case possible.
We had a
UserAction
entity with a composite id consisting of propertiesuserId, action, objectId
.An entity referenced a set of
UserAction
s via a collection table and in a view, we wanted to visualize the set ofUserAction
s in a paginated table grouped by userId.Apart from the group by not being allowed, the entity view also required that the id attribute must match the id attribute of the entity. Since group by is used, this would actually not be necessary.
First we should think about lifting the requirement that group by is not allowed with paginated criteria builders.
Finally we might also want to make it possible to define a "custom" id attribute that must not match the entities id attribute. (This will always require a group by?)
The text was updated successfully, but these errors were encountered: