0

I am trying to fetch the FileRepository row with maximum version for a particular fileId. But following exception is thrown:

java.lang.ClassCastException: java.lang.Integer cannot be cast to com.xxx.xxx.xxx.FileRepository

fileRepo = (FileRepository)session.createCriteria(FileRepository.class,"fileRepository")
                   .createAlias("fileRepository.file", "file")
                   .add(Restrictions.eq("file.fileId", file.getFileId()))
                   .setProjection(Projections.max("version")).uniqueResult();
Iamat8
  • 3,888
  • 9
  • 25
  • 35
Forkmohit
  • 733
  • 3
  • 12
  • 31

1 Answers1

2
.setProjection(Projections.max("version")).uniqueResult();

Projection means receiving particular column values instead of rows.

If you see this making returning the ciriteria only version number which is an Int. Hence the error.

Either remove this projection or receive an int.

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307