search

Home  >  Q&A  >  body text

java - I have a hql question and it has been frustrating me for a day.

@SuppressWarnings("JpaQlInspection")

@Override
public String queryUGI(String openid, String ka) {
    String hql="from UserGameInformation as ugi where ugi.ka=?0 and ugi.openid=?1";
    Session session = this.getSession();
    Query query = session.createQuery(hql);
    query.setParameter(0, ka);
    query.setParameter(1,openid);
    UserGameInformation userGameInformation = (UserGameInformation)query.list().get(0);
    String result=userGameInformation.getTime();
    return result;
}

This is my hql for operating the database

@RequestMapping(value = "/summary",method= RequestMethod.POST)

@ResponseBody
public void summary(HttpServletRequest request)
{
    String ka = request.getParameter("ka");
    String time = request.getParameter("time");
    HttpSession session = request.getSession();
    UserEntity userEntity = (UserEntity) session.getAttribute("user");
    String t = userGameInformationService.queryUGI(userEntity.getOpenid(),ka);
    if(t==""){
        System.out.println("dkhdhfkdfhkldf");
        UserGameInformation ugi = new UserGameInformation();
        ugi.setOpenid(userEntity.getOpenid());
        ugi.setKa(ka);
        ugi.setTime(time);
        userGameInformationService.addUserGameInformation(ugi);
    }
    else if(Integer.parseInt(t)<Integer.parseInt(time)){
      return;
    }
    else {
        UserGameInformation ugi = userGameInformationService.findUser(userEntity.getOpenid(),ka);
        ugi.setKa(ka);
        ugi.setTime(time);
        ugi.setOpenid(userEntity.getOpenid());
        userGameInformationService.updateUserGameInformation(ugi);
    }

}

Here I am making the call

It was originally available last night, but if you don’t know what happened today, it still doesn’t work. The debug execution goes to query.setParameter(0, ka); after this sentence, it jumps to other sources, and I just click on it. After adjusting to the next breakpoint, it is over. The console does not report an error, but the database does not change. I don’t know the reason. Please let me know. Thank you very much. . .

高洛峰高洛峰2878 days ago487

reply all(3)I'll reply

  • 某草草

    某草草2017-05-16 13:25:28

    Thank you all for your help. I have solved it. It’s not possible to use question marks in hql. You have to use colons. I can’t understand it either

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 13:25:28

    Single-step debugging. First remove the alias of hql

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-16 13:25:28

    Observe the value of t first, it is very likely that this condition is met
    Integer.parseInt(t)<Integer.parseInt(time)

    Null value is returned, so the data in the database has not changed.
    If not, check if there is anything wrong with your other related codes and change them.
    Also, I don’t know if your hql statement is correct. From what I understand, it should be written like this, such as
    from Student s where s.id=? and s.name=?

    reply
    0
  • Cancelreply