based on this example :
@Service
public class Purchase {
@PersistenceContext
private EntityManager em;
@Autowired
private PurchaseDAO dao;
private String normalField;
.... // methods, operations, etc
}
Please help correct me if im mistaken :
- The service class Purchase and the PurchaseDAO are singletons that are managed by spring
- The service class's field normalField is not threadsafe, because singleton is a single object shared by many
- Let's assume the @Repository-annotated-PurchaseDAO doesnt have any field, which means it's threadsafe, will be injected automatically by spring
- The EntityManager instance is also a threadsafe property because @PersistenceContext will make sure that the entityManager of the current transaction will be used.
Thank you !