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?
|