Code:
public static void initializeEntity(
final Object entity,
final boolean readOnly,
final SessionImplementor session,
final PreLoadEvent preLoadEvent,
final PostLoadEvent postLoadEvent) throws HibernateException {
...
final PersistenceContext persistenceContext = session.getPersistenceContext();
EntityEntry entityEntry = persistenceContext.getEntry(entity);
if ( entityEntry == null ) {
throw new AssertionFailure( "possible non-threadsafe access to the session" );
}
Looking at the implementation (code above) it seems that entityEntry == null in a place where it should never be null (if
working with an unique thread).
Therefore hibernate states that you probably are acceding the same session from another concurrent thread
and in this other thread you are removing entities from persistence context (for example by calling session.clear() or session.evict(entity) or session.close()).
You must check if in your application there are different thread sharing the same hibernate session,
that must be avoided.