Skip to content
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

Sub Query and Pagination throws an error #1936

Open
shopera007 opened this issue Sep 17, 2024 · 1 comment
Open

Sub Query and Pagination throws an error #1936

shopera007 opened this issue Sep 17, 2024 · 1 comment
Labels
component: core kind: bug worth: high Implementing this has a high worth

Comments

@shopera007
Copy link

It seems that I'm encountering an issue with Blaze Persistence related to a query that involves a join with a subquery and pagination. When pagination is applied, it throws the following error:

 An exception occurred while filtering products
java.lang.IllegalArgumentException: org.hibernate.query.SyntaxException: At 1:2216 and token 'entity_function', no viable alternative at input 'SELECT product.id'

However, when I remove pagination, the query works as expected. I've spent the last two days debugging and searching for a solution without success. Could you please assist me in resolving this?

Here is the code I'm trying to execute:

final CriteriaBuilder<Product> criteriaBuilder = this.criteriaBuilderFactory.create(this.entityManager, Product.class, "product");

final var entityViewSetting = EntityViewSetting.create(ProductCardView.class);
final var productViewCriteriaBuilder = this.entityViewManager.applySetting(entityViewSetting, criteriaBuilder);

productViewCriteriaBuilder.with(ProductViewHistoryCTE.class)
        .from(ProductViewHistory.class, "ProductViewCTE")
        .bind("productId").select("product.id")
        .bind("viewsCount").select("count(id)")
        .end();

productViewCriteriaBuilder.innerJoinOn(ProductViewHistoryCTE.class, "ProductViewCTE")
.on("ProductViewCTE.productId").eq("id")
.end();

final Sort sort = pageable.getSort();
if (sort.isSorted()) {
    EntityViewSortUtil.applySort(this.entityViewManager, ProductCardView.class, productViewCriteriaBuilder, sort);
}

return productViewCriteriaBuilder
        .page((int) pageable.getOffset(), pageable.getPageSize())
        .orderByAsc(Product_.ID)
        .withCountQuery(false)
        .withInlineCountQuery(false)
        .getResultList();
@beikov beikov added kind: bug component: core worth: high Implementing this has a high worth labels Oct 7, 2024
@beikov
Copy link
Member

beikov commented Oct 7, 2024

Hi and sorry it took so long for me to respond. This looks like a bug, but to be able to look into it more deeply, I'd need a reproducer. Could you please try to create one e.g. based on one of our quickstarts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: core kind: bug worth: high Implementing this has a high worth
Projects
None yet
Development

No branches or pull requests

2 participants