title: Hibernate: ClassCast Exception
body: <p>I am trying to fetch the <code>FileRepository</code> row with maximum version for a particular fileId. But following exception is thrown: </p>
  
  <blockquote>
    <p>java.lang.ClassCastException: java.lang.Integer cannot be cast to com.xxx.xxx.xxx.FileRepository   </p>
  </blockquote>
  
  <pre><code>fileRepo = (FileRepository)session.createCriteria(FileRepository.class,"fileRepository")
                     .createAlias("fileRepository.file", "file")
                     .add(Restrictions.eq("file.fileId", file.getFileId()))
                     .setProjection(Projections.max("version")).uniqueResult();
  </code></pre>