Is it possible to use @Transational worked in Spring, Eclipselink &Tomcat environment?

梦想与她 提交于 2019-12-25 01:43:11

问题


HiAll, I was confused by the EclipseLink for Tomcat documentation saying:

Limitations to JPA: No @PersistenceContext injection of a container managed persistence unit is available - use Persistence.createEntityManagerFactory(JTA_PU_NAME)

and, also by this question&answer:

but the typical JPA configuration in Spring looks like this, so you don't need to create EntityManager manually : @PersistenceContext private EntityManager em;

So, the question is: may I use this annotation @PersistenceContext for the entityManager to be sure that it will be created automatically and I dont need to create it manually?

Currently my @Transactional annotation does not work properly and I'm afraid it is because of creating the entity manager manually!

Please, need help.


回答1:


EclipseLink documentation says that @PersistenceContext is not handled by Tomcat on its own. However, if you use Spring, @PersistenceContext is handled by Spring, so that you can use it.

See also:

  • 13.5 JPA


来源:https://stackoverflow.com/questions/6705564/is-it-possible-to-use-transational-worked-in-spring-eclipselink-tomcat-enviro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!