I am trying to intercept the initialization of a proxy before it is loaded from the database by the cglib layer. I need this notification to potentially reconnect our long session before trying to load the object data, but the proxy initialization code does its own checks and throws an:
Code:
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session is disconnected
before things can get very far.
(Before being flamed I will just mention that we then keep this database connection (and transaction) going for the rest of the request, and then give it back to the pool. The reason for not getting the connection at start of every request is that many requests do not need database access.)
So my question is if there really should be an event in Hibernate that signals when a lazy object is being initialized, but that does not require that the lazy object's session is already connected?
Or if not, does anybody have another solution to this? (That is better than explicitly reconnecting the session before every potential lazy object access.)
Best regards
Mike