How to do it...

  1. First, we need to create our persistence unit (at persistence.xml):
    <persistence-unit name="ch02-jta-pu" transaction-type="JTA">        <provider>org.hibernate.ejb.HibernatePersistence</provider>                <jta-data-source>userDb</jta-data-source>        <non-jta-data-source>userDbNonJta</non-jta-data-source>                <exclude-unlisted-classes>false</exclude-unlisted-classes>        <properties>            <property name="javax.persistence.schema-             generation.database.action"              value="create"/>        </properties>    </persistence-unit>
  1. Then we create a User class as an entity (@Entity):
@Entitypublic class User implements Serializable {    private static final long serialVersionUID = 1L;    @Id    @GeneratedValue(strategy = GenerationType.AUTO)    private Long id;        private String name;

Get Java EE 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.