java - I have a hql question and it has been frustrating me for a day.
高洛峰
高洛峰 2017-05-16 13:23:28
0
3
399

@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. . .

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(3)
某草草

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

曾经蜡笔没有小新

Single-step debugging. First remove the alias of hql

Peter_Zhu

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=?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!