Commits

Micha Kops committed afb1135

New lifecycle events added.

Comments (0)

Files changed (3)

 			<groupId>junit</groupId>
 			<artifactId>junit</artifactId>
 			<version>4.11</version>
+			<scope>test</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.hamcrest</groupId>
 			<artifactId>hamcrest-all</artifactId>
 			<version>1.3</version>
+			<scope>test</scope>
 		</dependency>
 	</dependencies>
 

src/main/java/com/hascode/tutorial/entity/listener/BookEntityListener.java

 package com.hascode.tutorial.entity.listener;
 
 import javax.persistence.PostLoad;
+import javax.persistence.PostPersist;
+import javax.persistence.PostRemove;
+import javax.persistence.PostUpdate;
 import javax.persistence.PrePersist;
 import javax.persistence.PreRemove;
 import javax.persistence.PreUpdate;
 		System.out.println("prePersist: " + book.toString());
 	}
 
+	@PostPersist
+	public void postPersist(final Book book) {
+		System.out.println("postPersist: " + book.toString());
+	}
+
 	@PreUpdate
 	public void preUpdate(final Book book) {
 		System.out.println("preUpdate: " + book.toString());
 	}
 
+	@PostUpdate
+	public void postUpdate(final Book book) {
+		System.out.println("postUpdate: " + book.toString());
+	}
+
 	@PostLoad
 	public void postLoad(final Book book) {
 		System.out.println("postLoad: " + book.toString());
 		System.out.println("preRemove: " + book.toString());
 	}
 
+	@PostRemove
+	public void postRemove(final Book book) {
+		System.out.println("postRemove: " + book.toString());
+	}
+
 }

src/test/java/it/BookIT.java

 
 		book.setPublished(new Date());
 		em.persist(book);
+		em.flush();
 		em.refresh(book); // we just want to trigger postLoad
 
 		Book book2 = em.find(Book.class, 1L);
 		assertThat(book2.getTitle(), is(book.getTitle()));
 
 		em.remove(book2);
+		em.flush();
 	}
 
 	@Test(timeout = 10000, expected = PersistenceException.class)