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

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -