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

Failed JPASubQuery with count() in projection (Causes parse error in OpenJPA) #1329

mats42 opened this issue Apr 22, 2015 · 1 comment


Copy link

@mats42 mats42 commented Apr 22, 2015

I tried to get the following (stripped down) query to work:

JPAQuery query = new JPAQuery(logEntityManager);
QMessageLog messageLog = QMessageLog.messageLog;
QMessageLog otherMessageLog = new QMessageLog("otherMessageLog");

List<MessageLogProjection> messageLogResult = query.
    new QMessageLogProjection(
      new JPASubQuery().from(otherMessageLog).where(otherMessageLog.originalMessageNumber.eq(messageLog.messageNumber)).count())
public class MessageLogProjection {
  public MessageLogProjection(MessageLog messageLog, Long newCount) {

but it causes an error in OpenJPA:

org.apache.openjpa.persistence.ArgumentException: An error occurred while parsing the query filter "select messageLog_, (select count(otherMessageLog) from MessageLog otherMessageLog_ where otherMessageLog_.originalMessageNumber = messageLog_.messageNumber) from MessageLog messageLog_". Error message: Attempt to query field "otherMessageLog" from non-entity variable "otherMessageLog". Perhaps you forgot to prefix the path in question with an identification variable from your FROM clause?

To me it seems that the entity name in count(otherMessageLog) is missing an underscore and should have been count(otherMessageLog_) instead or am I missing something?

If I replace count() in the sub query with eg unique( (which also results in a Long) the query works.

I'm new to QueryDSL and unsure about which query constructions that is supported...
Is it a bug or am I doing something wrong? Can it be worked around?

Versions used was: OpenJPA 2.3.0 and QueryDSL 3.6.3

@timowest timowest added the progress label Apr 27, 2015
@timowest timowest added this to the 3.6.4 milestone May 16, 2015
Copy link

@johnktims johnktims commented May 31, 2015

Fixed in #1332 .

@johnktims johnktims closed this May 31, 2015
@timowest timowest removed the progress label May 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.