java - Passing EntityManager object to all BusinessLayer methods -
i know if passing reference entitymanager object businesslayer methods anti-pattern or no.
public void setcost(entitymanager em, int idproduct); public void updateproduct(entitymanager em, productentity product);
i find pattern practical since let me manage grouping of muliple methods build personalised transactions...
public void initproduct(entitymanager em, productentity product) { ... tx.begin() ... setcost(em, idproduct); updateproduct(em, product); ... tx.commit(); }
ps:
- i not using spring framework.
- the jpa based business layer , data access layer intended used in desktop app.
thanks
it seems unnecessary effort pass parameter, since can inject easier through @persistencecontext
.
or if don't have dependency injection container, might want turn responsibility other way around anyways. instead of passing entitymanager parameter, have implementation fetch somewhere (e.g. jndi).
Comments
Post a Comment