Archimedes Trajano (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZDE5YjYyM2Ix...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-17052?atlOrigin=eyJpIjoiZDE5Yj...
) HHH-17052 (
https://hibernate.atlassian.net/browse/HHH-17052?atlOrigin=eyJpIjoiZDE5Yj...
) When doing an entityManager find with an entity graph the pulled data does not have the
entity loaded unless the existing entity is detached (
https://hibernate.atlassian.net/browse/HHH-17052?atlOrigin=eyJpIjoiZDE5Yj...
)
Change By: Archimedes Trajano (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
I have a code
{noformat} // entity is an Entity that contains OneToMany collections
// I need this detach() for the following find() to provide me a managed entity that
// contains the collections loaded. Otherwise, `loaded` still has the collections
uninitialized.
entityManager.detach(entity);
final var entityType = entityManager.getMetamodel().entity(entity.getClass());
final var entityGraph = entityManager.getEntityGraph(entityType.getName());
final var loaded =
entityManager.find(
entity.getClass(),
entity.getId(),
Map.of(
SpecHints.HINT_SPEC_LOAD_GRAPH,
entityGraph,
SpecHints.HINT_SPEC_CACHE_RETRIEVE_MODE,
CacheRetrieveMode.BYPASS));{noformat}
I put in the workaround I had to do, but ideally it should either replace the {{entity}}
with the newly loaded one since it’s managed already when I do the find with the entity
graph hint.
But ideally I think [Allow passing in an entity graph on EntityManager.refresh ·
hibernate/hibernate-orm · Discussion #7152
(
github.com)|https://github.com/hibernate/hibernate-orm/discussions/7152] would look
cleaner.
Here is more context of my workaround [java - Hibernate: best practice to pull all lazy
collections - Stack
Overflow|https://stackoverflow.com/questions/19928568/hibernate-best-prac...]
(
https://hibernate.atlassian.net/browse/HHH-17052#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-17052#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100234- sha1:9e2db29 )