java - looking up entity manager in EJB Helper classes -
i trying inject entity manager in helper class, can pass helper session bean, problem need use entity manager in static init block of helper class (some thing like):
class mysessionbeanhelperclass { // staff here... static { someclass s = new someclass(entitymanager); } }
so, think way lookup entity manager instead of injecting it. , using passed sessioncontent not work here. (is it????) (this first question)
the second question is: if used ordinary way lookup resource (in case entity manager) (something following:)
context ic = new initialcontext(); em = (entitymanager) ic.lookup("java:comp/env/persistence/em");
is convert transactions used entity manager bean-managed transaction??
thanks!
i don't think it's idea static initializer. have sure necessary services (such jndi, jpa) before lookup occurs, can't guarantee when static initializer.
it's known problem in ejb there no "standard" way of performing one-time task upon app. start/stop, can use trick in following link:
how perform db cleanup operation upon shutdown in ejb container
the example performing action upon app. stop, can override servlet#init
instead.
Comments
Post a Comment