Take the tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

When i click on login, it checks the DB if there is a value matching then i get this error, else it does print me null.

public Login authenticate(Login login) {
         String query = "SELECT 1 FROM Login AS l WHERE l.email=? AND l.password=?";
         Object[] parameters = { login.getEmail(), login.getPassword() };
         List resultsList = getHibernateTemplate().find(query,parameters);
         if (resultsList.isEmpty()) {            
         }
         else if (resultsList.size() > 1) {

         }
         else {
           Login login1 = (Login) resultsList.get(0);
           System.out.println("Hello" + login1);
           return login1;
         }       
       return null;  
}

Error below

Cause: java.lang.ClassCastException: java.lang.Integer cannot be cast to com.intermedix.domain.Login at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:507) at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161) at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1154) at com.vaadin.ui.Button.fireClick(Button.java:371) at com.vaadin.ui.Button.changeVariables(Button.java:193) at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1094) at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:590) at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:266) at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:476) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230) at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:326) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to com.intermedix.domain.Login at com.intermedix.services.LoginService.authenticate(LoginService.java:34) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:301) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy32.authenticate(Unknown Source) at com.intermedix.ui.LoginDailog.checkLogin(LoginDailog.java:106) at com.intermedix.ui.LoginDailog.access$0(LoginDailog.java:102) at com.intermedix.ui.LoginDailog$1.buttonClick(LoginDailog.java:52) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:487) ... 26 more

share|improve this question
 
I'd possibly take the time to re-read about the Hibernate query language. –  David Bullock Jan 10 '11 at 14:50
add comment

2 Answers

up vote 6 down vote accepted

Perhaps you want to SELECT l (L-letter) rather than SELECT 1 (the number 1)? When you select a number, the number is returned. Hence the Integer

Or if this 1 is meant to be the limit, then use query.setMaxResults(1)

share|improve this answer
 
No, he just needs SELECT FROM, same as his last question. –  David Bullock Jan 10 '11 at 14:51
 
well, technically he can only use FROM Login ;) –  Bozho Jan 10 '11 at 14:56
 
I changed my query into String query = "SELECT L FROM Login AS L WHERE L.email=? AND L.password=?"; and it worked.... Thats Bozho always there to help –  theJava Jan 10 '11 at 15:07
 
Nice catch +1 –  Arthur Ronald F D Garcia Jan 11 '11 at 2:29
add comment

your List should be of Login

List<Login> resultList = (getHibernateTemplate().find(query,parameters);

then, when you make this:

Login login1 = (Login) resultsList.get(0);

you'll be getting an Instance of Login, and will not be trying to cast anything, but the Object Login to itself.

share|improve this answer
 
i get the same error –  theJava Jan 10 '11 at 15:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.