For a Swing application, I will choose one EntityManager per action, since it is quite cheap to create it, and you may not want to retain so many privileges that EntityManager manages when you do not use it (this is one EntityManager per application).
For a web application, a typical template is the "OpenSessionInView" template ( Session applied to Hibernate, but it can also be applied to EntityManager , since both logically provide the same role / functionality).
More details here: https://community.jboss.org/wiki/OpenSessionInView
Hope this helps.
source share