jakartaee / jakartaee/persistence
Allow passing in an entity graph on EntityManager.refresh
- Dominant language
- Java
- Stars
- 268
- Forks
- 78
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 13
Description
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.
Contributor guide
Research direction
Start by reviewing the EntityManager.refresh entry point and the entity graph options shown in the issue, then inspect the Jakarta Persistence API and specification guidance for refresh semantics. Determine how loadgraph and fetchgraph should behave during refresh and what tests or specification updates would demonstrate completion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100