How to do it...

  1. Let's begin by creating an entity (you can see it as a table):
@Entitypublic class User implements Serializable {    private static final long serialVersionUID = 1L;    @Id    @GeneratedValue(strategy = GenerationType.AUTO)    private Long id;        private String name;    private String email;    protected User() {    }         public User(Long id, String name, String email) {        this.id = id;        this.name = name;        this.email = email;    }    //DO NOT FORGET TO IMPLEMENT THE GETTERS AND SETTERS}
  1. Here we declare our persistence unit (at persistence.xml):
    <persistence-unit name="ch02-jpa-pu" transaction-type="JTA">        <provider>org.hibernate.ejb.HibernatePersistence</provider>        <jta-data-source>userDb</jta-data-source>         <exclude-unlisted-classes>false</exclude-unlisted-classes> ...

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.