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

43 views
Skip to first unread message

Mats

unread,
Apr 9, 2015, 3:20:10 AM4/9/15
to quer...@googlegroups.com
Hi,

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.
 
from(messageLog).
 
where(filter).
  list
(
   
new QMessageLogProjection(
      messageLog
,
     
new JPASubQuery().from(otherMessageLog).where(otherMessageLog.originalMessageNumber.eq(messageLog.messageNumber)).count())
   
);

@Immutable
public class MessageLogProjection {
 
...
 
@QueryProjection
 
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(otherMessageLog.id) (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?

Thanks!
/Mats

timowest

unread,
Apr 15, 2015, 4:01:56 PM4/15/15
to quer...@googlegroups.com
Hi.

Could you create an issue for it on GitHub?

Timo

Mats

unread,
Apr 22, 2015, 5:18:54 AM4/22/15
to quer...@googlegroups.com
Sorry for the delay, I've created an issue #1329 now.

By the way, thanks a lot for an excellent framework. It's way nicer to work with than anything else I've tried in Java!

Thanks,
/Mats

timowest

unread,
Apr 22, 2015, 2:25:51 PM4/22/15
to quer...@googlegroups.com
Hi Mats.

Thanks for your kind words!

Timo
Reply all
Reply to author
Forward
0 new messages