休眠更新查询中的值未更新

kar*_*ark 1 java hibernate hql

我正在JSF使用Hibernate作为ORM映射工具的应用程序上工作。

问题: 我正在MySQL用作数据库,所以我Mysql通过休眠将数据添加到其中。

现在我正在尝试从bean类更新数据库值

当我尝试更新它时,查询将成功执行,但更新后的值将不会添加到数据库中

我的Bean类代码:

 Session session=HibernateUtil.getSessionFactory().openSession();
 Query hQuery=session.createQuery("update Record set status='Present' where refId=100");
 System.out.println("Result : "+hQuery.executeUpdate());
Run Code Online (Sandbox Code Playgroud)

上面的代码用于更新表“ record”中的数据库值,其显示输出无错误,但数据库中的值未更新。

 Hibernate : update sample.record set Status='Present' where RefId=100
 Result    : 9
Run Code Online (Sandbox Code Playgroud)

在控制台中显示的上述结果中, showSql

任何建议将不胜感激...

kar*_*ark 5

我犯了一个错误,这是在提交休眠事务时 ...

更新的Bean类

      Transaction tx=null;
      Session hSession=HibernateUtil.getSessionFactory().openSession();
      Query hQuery=hSession.createQuery("update Leaverecord set status='HR' where refId="+lrb.getRefId());
      System.out.println("Result : "+hQuery.executeUpdate());
      tx=hSession.beginTransaction();
      tx.commit();
        hSession.close();
Run Code Online (Sandbox Code Playgroud)

输出量

Hibernate: update sample.record set Status='Present' where RefId=100
Result : 9
Run Code Online (Sandbox Code Playgroud)

我犯的错误是我没有在休眠更新查询中使用事务,我认为事务查询仅用于休眠插入。

现在一切正常...