-->
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: Projections
PostPosted: Fri Jul 24, 2009 3:37 pm 
Newbie

Joined: Fri Jul 24, 2009 3:19 pm
Posts: 2
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.


Top
 Profile  
 
 Post subject: Re: Projections
PostPosted: Fri Jul 24, 2009 6:21 pm 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
Quote:
Criteria projectionCriterion = HibernateUtil.currentSession().createCriteria(AccountStatusVO.class);

...

List temp = this.list(Integer.class, (Criterion) projectionCriterion);


https://www.hibernate.org/hib_docs/v3/a ... erion.html

https://www.hibernate.org/hib_docs/v3/a ... teria.html

Criteria is not a Criterion!

Greetings Michael


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.