Sorry for using the wrong words in the topic title, what I want to do is get notified
a) when a proxy is created instead of fetching an entity from the database
b) when the proxy is replaced with the entity it represents
The purpose is to log how long each proxy lives, as we suspect some of our lazy associations are fetched straight away. Ideally, it would be similar to EventListener, say onProxyCreation(Object proxy, Class entityClass, Serializable id) and onProxyReplacement(Object proxy, Object entity, Serializable id).
We could then use this to log a warning when a proxy lives for less than eg 100ms.
We are currently using Hibernate 5.6 without JPA (ie using Session interface).