snorbi
snorbi

Reputation: 2900

What is the QueryDSL equivalent of the JPQL `index()` function?

For example how can I convert the following JPQL query to QueryDSL?

SELECT p
FROM F f
JOIN f.p p
WHERE index(p)=0

where F.p is of type List<P>.

Upvotes: 1

Views: 605

Answers (1)

R&#233;mi Bantos
R&#233;mi Bantos

Reputation: 1967

You have to use the get() method in ListPath which implements the index() function.

Just as an example, here is a JPA query (QueryDSL 4.0.6) which gets a catalog entity whose second child category (index 1) has given name:

public Catalog findSecondCatalogChildCategoryByName(String Name) {
    return new JPAQueryFactory(entityManager)
            .selectFrom(catalog)
            .where(
                    catalog.rootCategories.get(1).name.eq(name)
            ).fetchOne();
}

Note: In this example, rootCategories field has java.util.List type

Upvotes: 1

Related Questions