From 08bf9b9fb3b686622c119677b62d86a696205b7c Mon Sep 17 00:00:00 2001 From: Gavin King Date: Fri, 20 Sep 2024 23:12:34 +0200 Subject: [PATCH] add overload of refresh() accepting an EntityGraph see issue #437 Signed-off-by: Gavin King --- .../jakarta/persistence/EntityManager.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/api/src/main/java/jakarta/persistence/EntityManager.java b/api/src/main/java/jakarta/persistence/EntityManager.java index 80b41a19..df61bc19 100644 --- a/api/src/main/java/jakarta/persistence/EntityManager.java +++ b/api/src/main/java/jakarta/persistence/EntityManager.java @@ -885,6 +885,26 @@ void refresh(Object entity, LockModeType lockMode, void refresh(Object entity, RefreshOption... options); + /** + * Refresh the state of the given managed entity instance from the + * database, along with all associated entities reachable by + * following the given {@link EntityGraph}, overwriting changes + * made to the entity, if any. This operation does not cascade to + * associations marked {@link CascadeType#REFRESH cascade=REFRESH} + * unless they are included in the given entity graph. + * @param entity a managed entity instance + * @throws IllegalArgumentException if the instance is not an entity + * or if the entity is not managed + * @throws TransactionRequiredException if there is no + * transaction when invoked on a container-managed + * entity manager of type + * {@link PersistenceContextType#TRANSACTION} + * @throws EntityNotFoundException if the entity no longer exists in + * the database + * @since 4.0 + */ + void refresh(T entity, EntityGraph entityGraph); + /** * Clear the persistence context, causing all managed entities to * become detached. Changes made to entities that have not already