Hey guys, I'm new to posting in Hibernate forums, so let me know if I leave out any pertinent info. Anyways, I'm simply trying to find the highest id in a given table - basically, "Select MAX(<id>) From <table>". Pretty easy. Here's my code for it:
Code:
ProjectionList proList = Projections.projectionList();
proList.add(Projections.max("AccountStatusID"));
Criteria projectionCriterion = HibernateUtil.currentSession().createCriteria(AccountStatusVO.class);
projectionCriterion.setProjection(proList);
// Projections.groupProperty("id.variableId",true);
List temp = this.list(Integer.class, (Criterion) projectionCriterion);
int max = ((Integer) temp.get(0)).intValue();
return max;
But I keep getting an error, and I cannot find out why:
Code:
java.lang.ClassCastException: org.hibernate.impl.CriteriaImpl
at com.dispatch.eCommerce.shop.service.impl.AccountStatusService.getMAXAccountStatusID(AccountStatusService.java:113)
at com.dispatch.eCommerce.shop.action.AdminAction.execute(AdminAction.java:1176)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Unknown Source)
Now, where I try to 'list' the query I've created, I have changed that class specification from 'int' to 'Integer' to 'AccountStatusVO', but all to no avail. I don't know what I'm missing here, but if someone could help me out and explain what I've done wrong and how, that'd be great.