Add Hibernate interceptor to a session factory on run time -
i wish add interceptor session or session factory on run time. managed event handlers:
@component public class hibernateeventlistenersregisterer { /** post load event listener. */ @resource private genericpostloadeventlistener postloadeventlistener; /** session factory. */ @resource private sessionfactory sessionfactory; /** * register event listeners. */ @postconstruct public void registereventlisteners() { eventlistenerregistry registry = ((sessionfactoryimpl) sessionfactory).getserviceregistry() .getservice(eventlistenerregistry.class); registry.geteventlistenergroup(eventtype.post_load).appendlistener(postloadeventlistener); } }
i want use interceptor same way... can i?
no, can't. instead:
create interceptor or listener added permanently, accessible add/remove delegate interceptors/ listeners (or otherwise switchably enable/ or delegate functionality).
then, once can reference @ run-time (static singleton may easy way), can programatically switch on/off functionality or add/remove delegates.
(i've done related hibernate generators, delegating according deployed database type; , worked.)
note: fly in ointment here, configuration & startup; initialization events won't passed delegates, aren't created yet.
Comments
Post a Comment