Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
trajano opened this issue Aug 9, 2023 · 2 comments
Open

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

trajano opened this issue Aug 9, 2023 · 2 comments
Labels
candidate-for-4 Good candidate for JPA 4

Comments

@trajano
Copy link

trajano commented Aug 9, 2023

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.

@gavinking
Copy link
Contributor

This would be useful, and will be easier to in light of the direction we've decided to take #383.

@gavinking gavinking added the candidate-for-4 Good candidate for JPA 4 label Aug 23, 2023
gavinking added a commit to gavinking/persistence that referenced this issue Sep 20, 2024
@gavinking
Copy link
Contributor

See #672

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
candidate-for-4 Good candidate for JPA 4
Projects
None yet
Development

No branches or pull requests

2 participants