We are designing an application using Spring-Hibernate where 6 threads run simultaneously. Each thread performs a different operation and inserts/updates a few records in common table(all threads work on common tables).
While we know that we can have just one single instance of EntityManagerFactory
, we are not sure how many instances of EntityManager
should we have? Should we create six entity managers(one for each thread)? How should we create the DAO? Should we just create one EntityManager
like following and use the same dao class for all the threads? I know EM specification says that it's not thread safe, but I read somewhere that injected EM in the case of spring are threadsafe(I wasn't convinced with the explanation, though).
@Trasactional
public class myAppDao {
@PersistenceContext
private EntityManager entityManager;
..
}
or should we do something different ?