Hi,
I have two model objects: Mailbox and Message. I'm trying to query for
all mailboxes that have unread messages _and_ returning the count of
unread messages at the same time.
I'm so close, but can't get the final step to work. Here is my
simplified model:
public class Mailbox extends Model {
public String name;
public List<Message> messages;
}
public class Message extends Model {
public String subject;
public Boolean isUnread;
}
Here is what works:
JPA.em().createQuery("select
mbx.name, count(
message.id) from
Mailbox mbx join mbx.messages as message where message.isUnread = true
group by
mbx.name");
The above query returns a list with a string (mailbox name) and an
integer (unread message count).
However, trying to get the query to return Mailbox objects does not
work:
JPA.em().createQuery("select mbx, count(
message.id) from Mailbox
mbx join mbx.messages as message where message.isUnread = true group
by mbx");
It fails with:
A javax.persistence.PersistenceException has been caught,
org.hibernate.exception.SQLGrammarException: could not execute query
I'm running this against the test server, if that makes a difference.
Any suggestions are welcome!
Thanks,
Rico