Hibernate、在线数据库和UPDATE
我们目前正在规划一个应用程序,并希望使用 Hibernate。应用程序的数据库将是在线数据库,但应用程序应该能够在离线模式下工作。因此,您可以从数据库加载一个对象,关闭连接,使用该对象,然后可能会在数据库中更新它。 现在的问题是(嗯,据我所知)每次修改对象时,Hibernate 都会对数据库执行 UPDATE,这意味着如果同时关闭连接,它会抛出异常。 我现在的问题是:Hibernate 是否可以配置为在某个手动指定的时间执行更新?
We are currently planning an application and are looking to use Hibernate. The database for the application will be an online one, but the application should be able to work in an offline mode. So, you can load an object from the database, close the connection, play around with the object and maybe later update it in the database.
The problem now is that (well, as far as I know) Hibernate performs an UPDATE on the database every timethe object is modified, meaning that it'd throw an exception if the connection was closed in the meantime.
My question is now: can Hibernate be configured to perform updates at some manually specified time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您并不完全理解 Hibernate 使用的 工作单元 的概念。
您可以在一个会话中加载该对象,然后关闭该会话,然后将该对象(或具有相同标识的另一个对象)合并到另一个会话中(以便在其间进行的对象修改将在该新会话中刷新)。同时,所有会话都可以关闭,并且分离的对象可以用作普通对象(如果您不尝试访问其未初始化的惰性属性)。
另请参阅:
It looks like you don't completely understand the concept of Unit of Work used by Hibernate.
You can load the object in one session, then close the session and later merge that object (or another object with the same identity) into another session (so that modification of the object made in between will be flushed in that new session). In the meantime all sessions can be closed, and detached object can be used as a normal object (if you don't try to access its uninitialized lazy properties).
See also: