What does CascadeType.REFRESH do?

What does CascadeType.REFRESH actually do?

Definition for him

When we update an object, all objects contained in this field are also updated

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

+60
java jpa
Sep 10 '09 at 6:34
source share
2 answers

CascadeType's individual descriptions may be a bit confusing, but there is an easy way to figure this out from the general case.

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

So EntityManager.refresh() is defined as:

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

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

+91
Sep 10 '09 at 6:57
source share

Retrieving via Refresh: Managed objects can be reloaded from the database using the update method:

The contents of the managed entity in memory are discarded (including changes, if any) and replaced by data that is retrieved from the database. This can be useful to ensure that the application is dealing with the latest version of an entity object, in case it could be changed by another EntityManager from the moment it was received.

Source: http://www.objectdb.com/java/jpa/persistence/retrieve

+3
Nov 26 '14 at 18:36
source share



All Articles