我是JSF和Hibernate的新手,所以我很抱歉如果这个问题在这里很简单。休眠设置布尔值
我正在使用MySQL数据库,我的用户表有一个布尔列。 Hibernate的映射的hbm.xml值作为
<property name="verified" type="boolean">
<column name="verified" not-null="true"/>
</property>
当我在NetBeans
update Users set verified = false where email = '[email protected]'
运行使用HQL查询窗口查询它完美地将布尔值true和false。但在我的帮助类我有这种方法来设置值
public void setIsVerified(Users user, Boolean isVerified){
Transaction tx = null;
try{
tx = session.beginTransaction();
Query q = session.createQuery("update Users set verified = :verified where email = :email");
q.setParameter("verified", isVerified);
q.setParameter("email", user.getEmail());
q.executeUpdate();
}catch(RuntimeException e){
if(tx != null)
tx.rollback();
throw e;
}
}
但它没有设置值。我试图手动设置值为q.setParameter("verified", true);
它也没有工作。 (电子邮件是唯一字段,我也尝试使用ID字段这是主键。)
有趣的部分是当我使用JUnit运行此方法时,它不会产生任何错误消息或警告。它看起来很完美,但不会更改数据库中的值。
任何提示将不胜感激,因为我没有收到任何消息,我不知道在哪里搜索。我不知道后台会发生什么。在此先感谢..
对不起,我打错了它。两者都是用户 –
非常感谢你。你不会相信,但我有'tx.commit()'的所有帮助方法。只是在嘲笑我自己。我只用了两天的时间......现在就工作了。 –
这是我第一次使用Hibernate。感谢这份文件。我会阅读。 –