0

我必须在活跃的用户中搜索并使用特定的关键字。我有UserUser_personal我在课堂上没有状态的user_personal课程,所以我曾经search通过,因为在课堂User_personalUser有一个Activeusers查找功能,User如下所示

protected void doPost(HttpServletRequest request, HttpServletResponse response) 
throws ServletException, IOException
{
    // TODO Auto-generated method stub
    HashMap<String,String> map = RequestToMap.getBody(request);
    JsonObject output = new JsonObject();
    JsonArray SearchArray = new JsonArray();
    boolean validToken=true;
    if(validToken == true){
        EntityManager em = Entitymanager.getEntitymanager();
        try{
            String name = map.get("fname");
            if(name!=null && !name.isEmpty()){
                List<User> user = User.search(name, em);
                if(user!=null && !user.isEmpty()){

                    for(User u :user){
                        if(User.ActiveUsers(em).contains(u)){
                            JsonObject personal_details = new JsonObject();
                            personal_details .addProperty("id",u.getId());
                            personal_details .addProperty("email", u.getUser_p().getEmail());
                            User current_user  = User.find(u.getUser_p().getEmail(), em);

                            personal_details.addProperty("status",current_user.getStatus().toString());
                            personal_details .addProperty("first_name", u.getUser_p().getFname());
                            personal_details .addProperty("last_name", u.getUser_p().getLname());
                            personal_details .addProperty("image",  u.getUser_p().getImage());
                            personal_details .addProperty("score",current_user.getScore());
                            SearchArray.add(personal_details);
                        }               
                    }
                    if((SearchArray.size()!=0))
                        output.add("searched_users",SearchArray);
                    else
                        output.addProperty(Constants.MESSAGE, "ACTIVE User not found. Try typing another name");
                }
                else
                    output.addProperty(Constants.MESSAGE, "User not found.Try typing another name");
            }
            else
                output.addProperty(Constants.MESSAGE, "Please type a name to search");
        }
        finally{
            if(em.getTransaction().isActive())
                em.getTransaction().rollback();
            em.close();
        }
    }

    response.setContentType("application/JSON");
    response.getWriter().println(output);
}

searchUser课堂上的功能

public static List<User> search(String name,EntityManager em) {
    List<User_personal> u_p = User_personal.search(name,em);
    Query p = em.createQuery("select c from User c where (c.status=:stat) and (c.user_p = :u_p)");
    p.setParameter("stat",Status.ACTIVE);
    p.setParameter("u_p", u_p);
    @SuppressWarnings("unchecked")
    List<User> result = p.getResultList();

    if (!result.isEmpty()) {
        return result;
    }
    return null;
}

searchUser_personal课堂上

public static List<User_personal> search(String str,EntityManager em) {
    Query q = em.createQuery("SELECT u FROM User_personal u WHERE lower(CONCAT(u.fname,u.lname)) LIKE lower(:name) ORDER BY LOCATE(CONCAT(u.fname,u.lname),lower(:given)), LENGTH(CONCAT(u.fname,u.lname))", User_personal.class);
    q.setParameter("given",str);
    q.setParameter("name", "%"+str+"%");
    @SuppressWarnings("unchecked")
    List<User_personal> result = q.getResultList();

    if (!result.isEmpty()) {
        return result;
    } 
    return null;
}

我有一个例外

  <pre>com.objectdb.o.InternalException: Unexpected internal exception
     com.objectdb.o.JPE.h(JPE.java:168)
     com.objectdb.o.ERR.f(ERR.java:66)
     com.objectdb.o.OBC.onObjectDBError(OBC.java:1560)
     com.objectdb.jpa.JpaQuery.getResultList(JpaQuery.java:728)
     com.professionalVerdict.model.User.search(User.java:99)
 com.professionalVerdict.servlet.SearchServlet.doPost(SearchServlet.java:53)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  </pre>

<pre>java.lang.NullPointerException
     com.objectdb.o.EXR$e.c(EXR.java:190)
     com.objectdb.o.VAR.aB(VAR.java:887)
     com.objectdb.o.VAR.aA(VAR.java:830)
     com.objectdb.o.BCN.o(BCN.java:305)
     com.objectdb.jpa.JpaQuery.getResultList(JpaQuery.java:719)
     com.professionalVerdict.model.User.search(User.java:99)
 com.professionalVerdict.servlet.SearchServlet.doPost(SearchServlet.java:53)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
</pre>

谁能帮我找出解决方案?

4

0 回答 0