Skip to content

Allow passing in an entity graph on EntityManager.refresh  #437

@trajano

Description

@trajano

At present I do the following to reload an entity such that all the fields in the entity graph provided are loaded

    entityManager.detach(entity);
    final var entityType = entityManager.getMetamodel().entity(entity.getClass());
    final var entityGraph = entityManager.getEntityGraph(entityType.getName());
    return (T)
        entityManager.find(
            entity.getClass(),
            entity.getId(),
            Map.of(
                "jakarta.persistence.loadgraph", // or "jakarta.persistence.fetchgraph"
                entityGraph,
                "jakarta.persistence.cache_retrieve_mode",
                CacheRetrieveMode.BYPASS));

It would be cleaner I think if I can simply do

    final var entityType = entityManager.getMetamodel().entity(entity.getClass());
    final var entityGraph = entityManager.getEntityGraph(entityType.getName());
    entityManager.refresh(entity, 
            Map.of(
                "jakarta.persistence.loadgraph", // or "jakarta.persistence.fetchgraph"
                entityGraph));
   // and no cache retrieve mode

To reload the entity with the graph that was provided.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions