@@ -0,0 +1,2980 @@
+package com.vladmihalcea.book.hpjp.hibernate.transaction;%0A%0Aimport java.sql.Statement;%0Aimport java.util.List;%0Aimport javax.persistence.Entity;%0Aimport javax.persistence.EntityManager;%0Aimport javax.persistence.EntityTransaction;%0Aimport javax.persistence.FetchType;%0Aimport javax.persistence.Id;%0Aimport javax.persistence.ManyToOne;%0Aimport javax.persistence.NamedEntityGraph;%0Aimport javax.persistence.Table;%0A%0Aimport org.hibernate.Session;%0Aimport org.hibernate.annotations.NaturalId;%0A%0Aimport org.junit.Test;%0A%0Aimport com.vladmihalcea.book.hpjp.hibernate.fetching.PostCommentDTO;%0Aimport com.vladmihalcea.book.hpjp.util.AbstractMySQLIntegrationTest;%0Aimport com.vladmihalcea.book.hpjp.util.AbstractOracleXEIntegrationTest;%0Aimport com.vladmihalcea.book.hpjp.util.AbstractPostgreSQLIntegrationTest;%0Aimport com.vladmihalcea.book.hpjp.util.AbstractSQLServerIntegrationTest;%0A%0A/**%0A * @author Vlad Mihalcea%0A */%0Apublic class ConsistencyTest extends AbstractMySQLIntegrationTest %7B%0A%0A    @Override%0A    protected Class%3C?%3E%5B%5D entities() %7B%0A        return new Class%3C?%3E%5B%5D%7B%0A            Post.class,%0A        %7D;%0A    %7D%0A%0A    @Test%0A    public void test() %7B%0A        EntityManager entityManager = null;%0A        try %7B%0A            entityManager = entityManagerFactory().createEntityManager();%0A            entityManager.unwrap( Session.class ).doWork( connection -%3E %7B%0A                connection.setAutoCommit( false );%0A                try(Statement statement = connection.createStatement()) %7B%0A                    statement.executeUpdate( %22delete from post%22 );%0A                    statement.executeUpdate( %22insert into post (title, id) values ('Post nr. 1', 1)%22 );%0A                    try%7B%0A                        statement.executeUpdate( %22insert into post (title, id) values ('Post nr. 1', 1)%22 );%0A                    %7D%0A                    catch (Exception e) %7B%0A                        LOGGER.error( %22Constraint%22, e );%0A                    %7D%0A                    statement.executeUpdate( %22insert into post (title, id) values ('Post nr. 2', 2)%22 );%0A                    connection.commit();%0A                %7D%0A                catch (Exception e) %7B%0A                    connection.rollback();%0A                %7D%0A            %7D );%0A%0A        %7D%0A        finally %7B%0A            if (entityManager != null) %7B%0A                entityManager.close();%0A            %7D%0A        %7D%0A    %7D%0A%0A    @Entity(name = %22Post%22)%0A    @Table(name = %22post%22)%0A    public static class Post %7B%0A%0A        @Id%0A        private Long id;%0A%0A        @NaturalId%0A        private String title;%0A%0A        public Post() %7B%0A        %7D%0A%0A        public Post(Long id) %7B%0A            this.id = id;%0A        %7D%0A%0A        public Post(String title) %7B%0A            this.title = title;%0A        %7D%0A%0A        public Long getId() %7B%0A            return id;%0A        %7D%0A%0A        public void setId(Long id) %7B%0A            this.id = id;%0A        %7D%0A%0A        public String getTitle() %7B%0A            return title;%0A        %7D%0A%0A        public void setTitle(String title) %7B%0A            this.title = title;%0A        %7D%0A    %7D%0A%0A%7D%0A

Add consistency test