您的位置:首页 > 产品设计 > UI/UE

hibernate事物问题-- Executing an update/delete query

2017-12-22 22:08 393 查看
hibernate在系统查询(update)而不是自然查询可以不开启事物,将更改放在缓存中,之后在提交事物

,但是在createNativeQuery(string).executeUpdate()必须开启事物,因为这个不能将更改放到缓存中,所以必须马上进行提交从而对数据库进行改变

NativeQuery q = hibernate.base.hibnatemeth.getInstance().getSession().createNativeQuery("insert into STUD_GB_STUD");
hibernate.base.hibnatemeth.getInstance().getSession().beginTransaction();
q.executeUpdate();


只有这样,才能正常的提交事物,同时可以使用Spring的@Transaction Spring会帮助你开启事物
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hibernate 数据库 string