-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: The case of the missing comma
PostPosted: Thu Sep 09, 2004 12:27 am 
Regular
Regular

Joined: Tue Jun 08, 2004 8:24 am
Posts: 57
I'm getting a strange error from hibernate (version 2.1, using postgresql 7.4.2) when I try to run one of my queries, telling me that I'm missing a comma somewhere. I've checked my query many times over and I can't see any place where a comma is missing.

The query was generated like this:

private static final String listQuery =
"select" +
" fileInfo," +
" fileData," +
" metaData," +
" max(metaData.accessDate) as maxDate" +
" from" +
" FileInformation as fileInfo," +
" FileData as fileData," +
" MetaData as metaData" +
" where" +
" fileInfo.user = :user and" +
" fileInfo.path like :path and" +
" fileData.fileInformation = fileInfo and" +
" metaData.fileInformation = fileInfo and" +
" metaData.accessDate = maxDate" +
" group by" +
" fileInfo" +
" having" +
" metaData.accessDate <= :accessDate";

public static List doListFiles(User user, String basePath, Date referenceDate) throws
HibernateException
{
Query query = currentSession().createQuery(listQuery); // currentSession returns a session retrieved from a session factory
query.setParameter("user", user);
query.setString("path", basePath + "%");
query.setDate("accessDate", referenceDate);
return query.list();
}

This results in the following exception:
net.sf.hibernate.QueryException: , expected in SELECT [select fileInfo, fileData, metaData, max(metaData.accessDate) as maxDate from com.whatever.data.FileInformation as fileInfo, com.whatever.data.FileData as fileData, com.whatever.data.MetaData as metaData where fileInfo.user = :user and fileInfo.path like :path and fileData.fileInformation = fileInfo and metaData.fileInformation = fileInfo and metaData.accessDate = maxDate group by fileInfo having metaData.accessDate <= :accessDate]

If I separate out the actual query shown in the exception, it comes out to this:

select
fileInfo,
fileData,
metaData,
max(metaData.accessDate) as maxDate
from
com.whatever.data.FileInformation as fileInfo,
com.whatever.data.FileData as fileData,
com.whatever.MetaData as metaData
where
fileInfo.user = :user and
fileInfo.path like :path and
fileData.fileInformation = fileInfo and
metaData.fileInformation = fileInfo and
metaData.accessDate = maxDate
group by
fileInfo
having
metaData.accessDate <= :accessDate

There are 3 commas, 4 fields in the select portion.
There are 2 commas, 3 fields in the from portion.
There are 0 commas, 1 field in the group by column.

What am I missing?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 2:38 am 
Regular
Regular

Joined: Tue Jun 08, 2004 8:24 am
Posts: 57
Update: It looks like this error is happening because I tried to assign an alias to the result of an aggragate function:

max(metaData.accessDate) as maxDate

This leads me to another question which I've posted in a separate thread.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.