hibernate - Use entity manager in CDI extension -
i want write cdi extension loads entities database (which in fact groovy scripts implement interface) , provide them beans, possible implementations of interface injected cdi. think of sth. following:
public class extensionclass implements extension { @inject entitymanager em; public void afterbeandiscovery(@observes final afterbeandiscovery event, final beanmanager manager) { entity entity = em.find(); //do sth entity... } } when try inject entity manager way, null (which not surprise me much, did not expect @inject work inside cdi extension class).
is possible access entity manager inside cdi extension somehow (via beanmanager example)? or have access db in way?
you have create producer entitymanager. however, wouldn't recommend doing inside of extension, it's not portable (it may work on implementations, 1 of grey areas). entities need produced instead of letting cdi container handle it. if need entities @ start of application recommend using @startup ejb spec.
Comments
Post a Comment