This content has been marked as final.
Show 1 reply
-
1. Re: Manually created Hibernate EntityManager vs. injected on
skajotde Nov 13, 2008 8:14 AM (in response to alexeinov)JBoss uses EnityManager which is involved with TransactioManager and em is proxy so em.find/em.save is thread safe.
Your code is also thread safe because beans are thread-safe but creating emtnity manager factory has high cost (6 seconds on my machine).Persistence.createEntityManagerFactory("em");
Should be invkoned once.
If you move creating emf to singleton then there is question if emf.createEntityManager(); has proper transaction if you are using annotations on beans. If you using transactional filter (eg. on web.xml in web apps) which global begin/commit transaction there should be no problem.