Search.session() does not work with session proxies

Description

Search.session() creates a LazyInitSearchSession that retrieves the actual underlying SearchSession lazily upon first access, and then caches it.

This means that, if you call Search.session on a Session proxy that relies on thread-locals to redirect calls to the actual session (e.g. sessionFactory.getCurrentSession(), or Spring EntityManager proxies), the resulting SearchSession will always delegate to the Session from the first thread. This is problematic for many reasons: thread-safety (a session will be accessed from concurrent threads), search (we'll retrieve entities from an unrelated session), indexing (we'll add indexing operations to the wrong session/transaction), ...

Environment

None
Fixed

Assignee

Yoann Rodière

Reporter

Yoann Rodière

Labels

None

Suitable for new contributors

None

Feedback Requested

None

Components

Fix versions

Priority

Major
Configure