Last active
March 16, 2017 16:27
-
-
Save thjanssen/88db6a0df440a03172ee568811e2cc84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| AuditReader auditReader = AuditReaderFactory.get(em); | |
| List revisionNumbers = auditReader.getRevisions(Book.class, b.getId()); | |
| for (Number rev : revisionNumbers) { | |
| Book auditedBook = auditReader.find(Book.class, b.getId(), rev); | |
| log.info(“Book [“+auditedBook+”] at revision [“+rev+”].”); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| AuditReader auditReader = AuditReaderFactory.get(em); | |
| Book auditedBook = auditReader.find(Book.class, b.getId(), created); | |
| log.info(“Book [“+auditedBook+”] at [“+created+”].”); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| EntityManager em = emf.createEntityManager(); | |
| em.getTransaction().begin(); | |
| Author a = new Author(); | |
| a.setFirstName(“Thorben”); | |
| a.setLastName(“Janssen”); | |
| em.persist(a); | |
| Book b = new Book(); | |
| b.setTitle(“Hibernate Tips”); | |
| b.getAuthors().add(a); | |
| a.getBooks().add(b); | |
| em.persist(b); | |
| em.getTransaction().commit(); | |
| em.close(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <dependency> | |
| <groupId>org.hibernate</groupId> | |
| <artifactId>hibernate-envers</artifactId> | |
| <version>5.2.5.Final</version> | |
| </dependency> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE TABLE revinfo | |
| ( | |
| rev integer NOT NULL, | |
| revtstmp bigint, | |
| CONSTRAINT revinfo_pkey PRIMARY KEY (rev) | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Book b = em.find(Book.class, b.getId()); | |
| b.setTitle(“Hibernate Tips – 64 Tips for your day to day work”) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment