diff --git a/jpademo/jpademo.iml b/jpademo/jpademo.iml
new file mode 100644
index 0000000..13d6ecc
--- /dev/null
+++ b/jpademo/jpademo.iml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/jpademo/pom.xml b/jpademo/pom.xml
new file mode 100644
index 0000000..9af52a4
--- /dev/null
+++ b/jpademo/pom.xml
@@ -0,0 +1,82 @@
+
+
+ 4.0.0
+ jpademo
+ jpademo
+
+
+ jeedemo
+ it.plague.jeedemo
+ 1.0-SNAPSHOT
+
+
+
+ UTF-8
+ 1.7
+ 1.7
+
+
+
+
+ org.eclipse.persistence
+ org.eclipse.persistence.jpa
+
+
+ org.hibernate
+ hibernate-validator
+
+
+ org.glassfish
+ javax.el
+
+
+ org.apache.derby
+ derbyclient
+
+
+ org.apache.derby
+ derby
+ test
+
+
+ org.projectlombok
+ lombok
+ provided
+
+
+ junit
+ junit
+ test
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.0
+
+ 1.7
+ 1.7
+
+
+
+ org.apache.maven.plugins
+ maven-failsafe-plugin
+ 2.12.4
+
+
+ integration-test
+
+ integration-test
+ verify
+
+
+
+
+
+
+
diff --git a/jpademo/src/main/java/it/plague/jeedemo/Book.java b/jpademo/src/main/java/it/plague/jeedemo/Book.java
new file mode 100644
index 0000000..b1f20d5
--- /dev/null
+++ b/jpademo/src/main/java/it/plague/jeedemo/Book.java
@@ -0,0 +1,37 @@
+package it.plague.jeedemo;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Entity
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+@NamedQueries({
+ @NamedQuery(name = "Book.findAll", query = "select b from Book b"),
+ @NamedQuery(name = "Book.findOneH2G2", query = "select b from Book b where b.title = 'H2G2'")
+})
+public @Data
+class Book {
+
+ @Id
+ @GeneratedValue
+ private Long id;
+ @NotNull
+ private String title;
+ private Float price;
+ @Size(min = 10, max = 2000)
+ private String description;
+ private String isbn;
+ private Integer nbOfPage;
+ private Boolean illustrations;
+}
diff --git a/jpademo/src/main/resources/META-INF/insert.sql b/jpademo/src/main/resources/META-INF/insert.sql
new file mode 100644
index 0000000..2c8e481
--- /dev/null
+++ b/jpademo/src/main/resources/META-INF/insert.sql
@@ -0,0 +1,3 @@
+insert into book(id, title, description, illustrations, isbn, nbofpage, price) values (1000, 'Beginning Java EE 6', 'Best Java EE book ever', 1, '1234-5678', 450, 49)
+insert into book(id, title, description, illustrations, isbn, nbofpage, price) values (1001, 'Beginning Java EE 7', 'No, this is the best', 1, '5678-9012', 550, 53)
+insert into book(id, title, description, illustrations, isbn, nbofpage, price) values (1010, 'The Lord of the Rings', 'One ring to rule them all', 0, '1234-5678', 222, 23)
diff --git a/jpademo/src/main/resources/META-INF/persistence.xml b/jpademo/src/main/resources/META-INF/persistence.xml
new file mode 100644
index 0000000..9835c63
--- /dev/null
+++ b/jpademo/src/main/resources/META-INF/persistence.xml
@@ -0,0 +1,40 @@
+
+
+
+
+ org.eclipse.persistence.jpa.PersistenceProvider
+ it.plague.jeedemo.Book
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ org.eclipse.persistence.jpa.PersistenceProvider
+ it.plague.jeedemo.Book
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/jpademo/src/test/java/it/plague/jeedemo/BookIT.java b/jpademo/src/test/java/it/plague/jeedemo/BookIT.java
new file mode 100644
index 0000000..765ed02
--- /dev/null
+++ b/jpademo/src/test/java/it/plague/jeedemo/BookIT.java
@@ -0,0 +1,70 @@
+package it.plague.jeedemo;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import javax.validation.ConstraintViolationException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class BookIT {
+
+ private EntityManager em;
+
+ @Before
+ public void initEntityManager() {
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpademoTestUnit");
+ em = emf.createEntityManager();
+ }
+
+ @After
+ public void closeEntityManager() {
+ if (em != null) {
+ em.close();
+ }
+ }
+
+ @Test
+ public void shouldCreateJavaEE7Book() {
+ Book book = em.find(Book.class, 1001L);
+ assertEquals("Beginning Java EE 7", book.getTitle());
+ }
+
+ @Test
+ public void shouldCreateH2G2Book() {
+ Book book = Book.builder()
+ .title("H2G2")
+ .description("The Hitchhiker's Guide to the Galaxy")
+ .price(12.5f)
+ .isbn("1-84023-742-2")
+ .nbOfPage(354)
+ .illustrations(false)
+ .build();
+
+ em.getTransaction().begin();
+ em.persist(book);
+ em.getTransaction().commit();
+ assertNotNull("ID should not be null", book.getId());
+
+ book = em.createNamedQuery("Book.findOneH2G2", Book.class).getSingleResult();
+ assertEquals("The Hitchhiker's Guide to the Galaxy", book.getDescription());
+ }
+
+ @Test(expected = ConstraintViolationException.class)
+ public void shouldRaiseConstraintViolationCauseNullTitle() {
+ Book book = Book.builder()
+ .title(null)
+ .description("Null title, should fail")
+ .price(12.5f)
+ .isbn("1-84023-742-2")
+ .nbOfPage(354)
+ .illustrations(false)
+ .build();
+ em.persist(book);
+ }
+}