CascadeType.REFRESH实际上做了什么? [英] What does CascadeType.REFRESH actually do?

查看:326
本文介绍了CascadeType.REFRESH实际上做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CascadeType.REFRESH 实际上做了什么?

它的定义是


当我们刷新实体时所有实体在这个字段中保持刷新

When we refresh an entity all the entities held in this field refresh too

但这在实践中意味着什么?有人可以给我一个简单的例子吗?

but what does this mean in practice? Could someone please give me a simple example?

推荐答案

各个CascadeType描述可能有点令人困惑,但有一个简单的方法从一般情况看出来。

The individual CascadeType descriptions can be a bit confusing, but there's an easy way to figure it out from the general case.

对于任何 CascadeType 值,这意味着如果操作<$使用 EntityManager 接口在实例上调用c $ c> X ,该实例引用了其他实体实例,并且该关联具有<定义了code> CascadeType.X ,然后 EntityManager 操作也将应用于该关联实体。

For any of the CascadeType values, it means that if operation X is called on an instance using the EntityManager interface, and that instance has references to other entity instances, and that association has CascadeType.X defined, then the EntityManager operation will also be applied to that associated entity.

所以 EntityManager.refresh()定义为:


从数据库
刷新实例的状态,覆盖对实体的
更改(如果有的话)。

Refresh the state of the instance from the database, overwriting changes made to the entity, if any.

因此,如果实体A具有对实体B的引用,并且该引用使用 @ CascadeType.REFRESH EntityManager.refresh(A),然后隐式调用 EntityManager.refresh(B)还有。

So if entity A has a reference to entity B, and that reference is annotated with @CascadeType.REFRESH, and EntityManager.refresh(A) is called, then EntityManager.refresh(B) is implicitly called also.

这篇关于CascadeType.REFRESH实际上做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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