public class DefaultReactiveLoadEventListener extends Object implements ReactiveLoadEventListener
org.hibernate.event.internal.DefaultLoadEventListener
. Note that sometimes Hibernate ORM calls org.hibernate.internal.SessionImpl#internalLoad(String, Serializable, boolean, boolean)
and #onLoad(LoadEvent, LoadType)
is called. We only support this case when loading generates a proxy.
The return value of the private methods loading the entity is a proxy or a CompletionStage
. The CompletionStage
only happens when we query the db and a proxy is not created. If #onLoad(LoadEvent, LoadType)
is called, we cannot get the entity loaded from the db without blocking the request and therefore we aren't going to support this case for now.
Constructor and Description |
---|
DefaultReactiveLoadEventListener() |
Modifier and Type | Method and Description |
---|---|
protected EntityPersister | getPersister(LoadEvent event) |
protected CompletionStage<Object> | loadFromDatasource(LoadEvent event, EntityPersister persister) Performs the process of loading an entity from the configured underlying datasource. |
void | onLoad(LoadEvent event, LoadEventListener.LoadType loadType) This method is not reactive but we expect it to be called only when a proxy can be returned. |
CompletionStage<Void> | reactiveOnLoad(LoadEvent event, LoadEventListener.LoadType loadType) Handle the given load event. |
public void onLoad(LoadEvent event, LoadEventListener.LoadType loadType) throws HibernateException
In particular, it should be called only by org.hibernate.internal.SessionImpl#internalLoad(String, Serializable, boolean, boolean)
.
UnsupportedOperationException
- if the entity loaded is not a proxyUnexpectedAccessToTheDatabase
- if it needs to load the entity from the dbHibernateException
org.hibernate.event.internal.DefaultLoadEventListener#onLoad(LoadEvent, LoadType)
public CompletionStage<Void> reactiveOnLoad(LoadEvent event, LoadEventListener.LoadType loadType) throws HibernateException
reactiveOnLoad
in interface ReactiveLoadEventListener
event
- The load event to be handled.HibernateException
protected EntityPersister getPersister(LoadEvent event)
protected CompletionStage<Object> loadFromDatasource(LoadEvent event, EntityPersister persister)
event
- The load eventpersister
- The persister for the entity being requested for load