分离的实体和管理的实体

分离的实体和管理的实体

本文介绍了分离的实体和管理的实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是独立实体?
如何在交易期间将管理实体转换为分离的实体?

What a "detached entity" means?How is it possible to convert a managed entity to a detached entity during a transaction?

推荐答案

分离的实体是不得由JPA提供者反映的实体。

A detached entity is an entity which state must not be reflected by the JPA provider.

换句话说,如果您更改其状态(即通过setter方法),这些更改将不会保存到基础数据库,因为JPA提供程序不必观察这样的实体。

In other words, if you change its state (i.e. through setters methods) these changes will not be saved to the underlying database, as the JPA provider doesn't have to "observe" such entities.

如果实体E1是一个托管实体,你可以让它分离调用(非常合理的命名)方法。您还可以使用将清除整个PersistenceContext并有效地使所有托管实体分离。

If entity E1 is a managed entity you can make it detached invoking (very reasonable named) method EntityManager#detach(E1). You can also use EntityManager#clear() which will clear whole PersistenceContext and effectively making all managed entities detached.

这篇关于分离的实体和管理的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 14:57