Preloader image

Tomcat + Java EE = TomEE, the Java Enterprise Edition of Tomcat. With TomEE you get Tomcat with JPA added and integrated and ready to go!

In a plain Servlet, Filter or Listener you can do fun things like injection of JPA EntityManager or EntityManagerFactory:

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.servlet.http.HttpServlet;
import javax.transaction.UserTransaction;

public class MyServet extends HttpServlet {

    private UserTransaction userTransaction;

    private EntityManager entityManager;

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


        try {
            entityManager.persist(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
            entityManager.persist(new Movie("Joel Coen", "Fargo", 1996));
            entityManager.persist(new Movie("Joel Coen", "The Big Lebowski", 1998));
        } finally {



No need to add even a single library! To make the above work all you need is a WEB-INF/persistence.xml file in your webapp like the following:

<persistence xmlns="" version="1.0">

  <persistence-unit name="movie-unit">

      <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>

DataSources will automatically be created if they haven’t be configured explicitly.

Download TomEE and you’re minutes away from a functioning JPA application on Tomcat.

Unresolved directive in <stdin> - include::apache-tomee.adoc[leveloffset=+1]