JPA: Implement JPA 2.0 INDEX(collectionelement) function

Bug #765710 reported by Maia Everett
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Querydsl
Fix Released
Undecided
Unassigned

Bug Description

For ordered collections, JPA 2.0 supports an INDEX function, which returns the position of the element in the list. Its support is, however, currently unavailable in QueryDSL.

In addition, currently, ListPath.get([index]) is broken in JPA. It attempts to use square brackets, which is invalid JPQL syntax (tested with OpenJPA 2.1.0).

Here are the proposed semantics.

1. Under JPA, evaluation of ListPath<T, Q>.get(EXPR):
- returns a new Q with an automatically generated alias name;
- the returned entity path is added to the query's FROM clause via LEFT JOIN <path dot notation> <autogenerated alias>;
- INDEX(<autogenerated alias>) = EXPR is added to the query's WHERE clause.

2. For more flexibility, QueryDSL can optionally support an indexOf operation of the following signature:

NumberPath<Integer> ListPath<T, Q>indexOf(Q path);

When this expression is evaluated:
- Q is added as an alias for this list path via LEFT JOIN, if it is not already there;
- The returned number path is aliased to INDEX(Q).

NumberPath<Integer> ListPath<T, Q>indexOf(T entity);

When this expression is evaluated:
- A new entity path is created with an autogenerated alias and added to LEFT JOIN.
- The returned number path is aliased to INDEX(<new path>).
- <new path> = T is added to the query's WHERE clause.

Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

Thanks for the detailed bug report. I will try to make indexed list access available also for other JPA providers. The current syntax is not JPA standard compliant, as you pointed out.

Changed in querydsl:
status: New → In Progress
Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

I just commited a fix to SVN trunk.

Changed in querydsl:
status: In Progress → Fix Committed
Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

Released in 2.2.0-beta4

Changed in querydsl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.