How to adapt persistence.xml file to connect JPA to a JDBC/MySQL database in Java EE environment (Tomcat + JSF)

我只是一个虾纸丫 提交于 2019-12-01 06:30:05

The given example requires JTA, Java Transaction API. It will delegate the transaction management to the container. With JTA enabled, if you're using a @Stateless EJB, then a single method call counts by default as a single complete transaction. This allows you to write clean code without any tx.begin, tx.commit, tx.rollback, etc boilerplate.

Like JSF, EJB and JPA, JTA is by default not available on a barebones JSP/Servlet container as Tomcat and Jetty. Like JSF, EJB and JPA, you'd need to install JTA separately on Tomcat.

An alternative is to switch from a JSP/Servlet container to a real Java EE (web profile) container, such as Glassfish, JBoss AS and TomEE. It offers everything directly out the box with regard to Java EE. Note that JBoss AS and TomEE basically use Tomcat's JSP/Servlet engine under the covers.

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