We're updating the issue view to help you get more done. 

SessionImpl.refresh() throws IllegalArgumentException, "Entity not managed" for detached instances when JPA bootstrapped

Description

We have the following method in our codebase:

Repository.java

1 2 3 4 5 6 7 8 public void refresh(Object obj) { if(entityManager().contains(obj)) { entityManager().refresh(obj); } else { // when not managed: refresh directly with the Hibernate Session ((Session)entityManager().getDelegate()).refresh(obj); } }

Here we depend on Hibernates implementation of EntityManager.refresh() without the jpa restriction that the entity has to be managed by the current persistance context.

Our code now fails in Hibernate 5.2. The SessionImpl.refresh(obj) method throws a "Entity not managed"-IllegalArgumentException in fireRefresh(event), because we are "jpa bootstraped" (SessionFactoryOptions.isJpaBootstrap()).

We don't use refresh() regularly in this way, but the hibernate way is nice to have in some cases. It would greatly appreciated if you could somehow integrate our use case back in (maybe with the bigger changes in 6.0?).

Environment

None

Status

Assignee

Andrea Boriero

Reporter

Torsten Schöne

Components

Fix versions

Affects versions

5.2.3

Priority

Major