Hibernate刷新不会更新数据库 [英] Hibernate flush doesn't update database

查看:113
本文介绍了Hibernate刷新不会更新数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用hibernate来存储来自Web服务的一组对象。



接收到的每个对象都使用hibernate保存。



接收对象包含在事务并且在收到最终对象后,所有对象都会出现在数据库中。

我现在试着让每个对象在保存时出现在数据库中。我试图用

  getHibernateTemplate()。saveOrUpdate(foo); 

getHibernateTemplate()。flush();
getHibernateTemplate()。clear();

我的理解是应该删除hibernate的缓存值并将值写入数据库。



任何学习或指导?

解决方案

感谢Brian的帮助。在另一个包装保存调用的类中,问题变成了 for 循环。



解决方案是删除循环中的,并用迭代器替换它



Hibernate为循环的整个保留了相同的事务。使用迭代器,Hibernate似乎开始了一个新的事务,因此在开始下一个事务之前执行对数据库的提交,然后执行flush。


I'm using hibernate to store a set of objects from a web service.

As the object are received each I am saving them using hibernate.

Receiving the objects is wrapped in a transaction and all the objects appear in the database after the final object is received.

I am now trying have each object appear in the database when saved. I've tried to achieve this with

getHibernateTemplate().saveOrUpdate( foo );

getHibernateTemplate().flush();
getHibernateTemplate().clear();

My understanding is this should remove the values hibernate's cache and write the values to the database.

Any learning or directions?

解决方案

Thanks for the help Brian. The problems turned out to be a for loop in another class wrapping the save call.

The solution was to remove the for loop and replace it with an iterator.

Hibernate was keeping the same transaction for the entire for loop. Using the iterator, Hibernate seems to start a new transaction and hence performs the commit to the database and then a flush before beginning the next transaction.

这篇关于Hibernate刷新不会更新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆