- 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}
- 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> ...