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

前端 未结 1 1528

I am developing a Dynamic web project (Java EE) using JSF, PrimeFaces, JPA, and running on Tomcat 7. The project development is based on http://www.simtay.com/simple-crud-we

1条回答
  •  北海茫月
    2021-01-14 00:47

    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.

    0 讨论(0)
提交回复
热议问题