0

我想在这里运行这个东西。

public List<String> getOnlineUsers(){
        List<User> d=sessionfactory.getCurrentSession().createQuery("from User").list();
        List<String> onlineUsers=null;
        List<Integer> timediff=null;
        for(int i=0;i<d.size();i++){
            timediff=(List<Integer>)sessionfactory.getCurrentSession().createQuery("SELECT TIMESTAMPDIFF(SECOND,'"+d.get(i).getLastUpdated()+"',now())").list();
        }
        for(int i=0;i<timediff.size();i++){
            System.out.println("time "+timediff.get(i));
            if(timediff.get(i)<=120){
                onlineUsers.add(d.get(i).getUsername());
            }
        }
        return onlineUsers;

    }

但我收到此错误消息

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.bind.annotation.support.HandlerMethodInvocationException: Failed to invoke handler method [public org.springframework.web.servlet.ModelAndView com.beingjavaguys.controller.HomeController.showOnlineUsers(java.lang.String,org.springframework.validation.BindingResult)]; nested exception is java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.MethodNode 
 \-[METHOD_CALL] MethodNode: '('
    +-[METHOD_NAME] IdentNode: 'TIMESTAMPDIFF' {originalText=TIMESTAMPDIFF}
    \-[EXPR_LIST] SqlNode: 'exprList'
       +-[IDENT] IdentNode: 'SECOND' {originalText=SECOND}
       +-[QUOTED_STRING] LiteralNode: ''2013-09-08 01:02:11.0''
       \-[METHOD_CALL] MethodNode: '('
          +-[METHOD_NAME] IdentNode: 'now' {originalText=now}
          \-[EXPR_LIST] SqlNode: 'exprList'

甚至无法思考错误消息。我看到这个的那一刻我就空白了。我想出它的原因是什么?

4

1 回答 1

1

我认为您必须传递有效的日期时间而不是文字作为 TIMESTAMPDIFF 中的第二个参数。

于 2013-09-07T21:15:03.110 回答