[hibernate-dev] Getting notified when session factory is completely set up

Hardy Ferentschik hardy at hibernate.org
Tue Feb 11 04:41:06 EST 2014


Hi,

not sure whether this could work in your use case, but in Search we use a SessionFactoryObserver.
We register the observer in Integrator#integrate with the SessionFactoryImplementor.
Once the SessionFactory is completely build you get a callback into SessionFactoryObserver#sessionFactoryCreated().

In Search we had the case that we did not want to complete bootstrapping at the integrator phase. Instead we defer 
this until the SessionFactory is completely build. 

Hope it helps.

—Hardy



On 11 Jan 2014, at 09:38, Gunnar Morling <gunnar at hibernate.org> wrote:

> Hi,
> 
> Is there a way for services (living in the SF-scoped registry) to get
> notified when the session factory has been set up and perform some action
> using that completely initialized factory?
> 
> Upon invocation of initiateService() of SessionFactoryServiceInitiator
> implementations, the passed factory is still under construction (the call
> originates from SessionFactoryImpl<init>), so I can't access all members.
> The same holds true for the StartStoppable contract in OGM which also sees
> a session factory under construction.
> 
> Now I could store the passed reference in a field and execute the required
> logic (some sort of validation) later on. I only have no meaningful hook to
> trigger such action exactly once. So I'd have to manage a flag to make sure
> the action is only performed once.
> 
> Is there a better way to achieve this?
> 
> Would it make sense to provide an additional contract to notify services
> about session factory lifecycle events:
> 
>    public interface SessionFactoryLifecycleAware extends Service {
> 
>        void onSessionFactoryLifecycleEvent(SessionFactoryImplementor sfi,
> Event event);
> 
>        public enum Event { POST_START, PRE_STOP }
>    }
> 
> ?
> 
> Thanks,
> 
> --Gunnar
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev




More information about the hibernate-dev mailing list