Seam - 如何分离实体
我正在研究 Seam 项目并遇到以下问题 - 有一个 ajax 编辑表单,并且与此表单的许多交互会影响(变异)底层实体并立即在数据库中更改,但我不希望这些更改仅在用户时才保留在数据库中将按“保存”按钮。我正在考虑分离实体来完成此任务,但想知道如何实现(也在寻找更智能的解决方案)。
I'm working on Seam project and have following problem - there is an ajax edit form and many interactions with this form affect (mutate) underlying entity and are changed in db immediately, but I wan't those changes persisted in database only when user will press "save" button. I'm thinking about deataching entity to accomplish this but wonder how (Also looking for smarter solutions).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您对实体所做的更改会立即反映出来,使其与数据库同步。要分离实体,您可以使用
entityManager.detach(object)
或entityManager.clear()
,但这将分离所有托管实体。EntityManager 的刷新模式默认为
FlushModeType.AUTO
,请尝试使用FlushModeType.COMMIT
,其中仅在显式提交/刷新时刷新更改。然后使用entityManager.flush()将持久化上下文同步到底层数据库。The changes that you are making to an entity are immediately reflected making it synchronized with database. To detach a entity, you can use
entityManager.detach(object)
orentityManager.clear()
, but that will detach all managed entities.EntityManager's flush-mode is
FlushModeType.AUTO
by default, instead tryFlushModeType.COMMIT
in which changes are flushed only on explicit commit/flush & then usingentityManager.flush()
to synchronize the persistence context to the underlying database.