Java 值未在hibernate更新查询中更新
我正在开发Java 值未在hibernate更新查询中更新,java,hibernate,hql,Java,Hibernate,Hql,我正在开发JSF应用程序,其中我使用Hibernate作为ORM映射工具 问题: 我使用MySQL作为数据库,所以我通过hibernate将数据添加到MySQL中 现在我正试图从bean类更新一个数据库值 当我尝试更新它时,查询将成功执行,但更新的值不会添加到数据库中 我的Bean类代码: Session session=HibernateUtil.getSessionFactory().openSession(); Query hQuery=session.createQuery("upd
JSF
应用程序,其中我使用Hibernate作为ORM映射工具
问题:
我使用MySQL
作为数据库,所以我通过hibernate将数据添加到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());
上面的代码是从表“record”更新数据库值,它在输出中没有显示错误,但在数据库中没有更新值
Hibernate : update sample.record set Status='Present' where RefId=100
Result : 9
在控制台中显示的上述结果中,对于showSql
如果您有任何建议,我们将不胜感激……您是否将该方法视为事务性的?例如:如果您使用springframework添加@Transactional注释您是否将该方法设置为事务性的?例如:如果您使用springframework添加@Transactional注释,我犯了一个错误,那就是提交hibernate事务 更新的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();
输出
Hibernate: update sample.record set Status='Present' where RefId=100
Result : 9
我犯的错误是没有在hibernate更新查询中使用事务,我认为事务查询只用于hibernate插入
现在它工作正常了…我犯了一个错误,那就是提交hibernate事务 更新的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();
输出
Hibernate: update sample.record set Status='Present' where RefId=100
Result : 9
我犯的错误是没有在hibernate更新查询中使用事务,我认为事务查询只用于hibernate插入
现在它工作正常了…是否检查了数据库中的值(如果更新了)?@vjamit..我发布这个问题只是出于这个原因。。数据库中的值未更新您提交您的事务??是否检查了数据库中的值(如果更新)?@vjamit..我发布此问题仅出于此原因。。数据库u中的值未更新,正在提交您的事务??您确定事务已提交到数据库吗?检查..您确定事务已提交到数据库吗?检查。。