|
Hibernate example source code file (TransitiveAuditParentsTest.java)
The Hibernate TransitiveAuditParentsTest.java source codepackage org.hibernate.envers.test.integration.superclass.auditparents; import org.hibernate.ejb.Ejb3Configuration; import org.hibernate.envers.Audited; import org.hibernate.envers.test.AbstractEntityTest; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.tools.TestTools; import org.hibernate.mapping.Column; import org.hibernate.mapping.Table; import org.junit.Assert; import org.junit.Test; import javax.persistence.EntityManager; import java.util.Set; /** * Tests mapping of child entity which parent declares one of its ancestors as audited with {@link Audited#auditParents()} * property. Child entity may mark explicitly its parent as audited or not. * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class TransitiveAuditParentsTest extends AbstractEntityTest { private long childImpTransId = 1L; private long childExpTransId = 2L; @Override public void configure(Ejb3Configuration cfg) { cfg.addAnnotatedClass(MappedGrandparentEntity.class); cfg.addAnnotatedClass(TransitiveParentEntity.class); cfg.addAnnotatedClass(ImplicitTransitiveChildEntity.class); cfg.addAnnotatedClass(ExplicitTransitiveChildEntity.class); } @Test @Priority(10) public void initData() { EntityManager em = getEntityManager(); // Revision 1 em.getTransaction().begin(); em.persist(new ImplicitTransitiveChildEntity(childImpTransId, "grandparent 1", "notAudited 1", "parent 1", "child 1")); em.getTransaction().commit(); // Revision 2 em.getTransaction().begin(); em.persist(new ExplicitTransitiveChildEntity(childExpTransId, "grandparent 2", "notAudited 2", "parent 2", "child 2")); em.getTransaction().commit(); } @Test public void testCreatedAuditTables() { Table explicitTransChildTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditparents.ExplicitTransitiveChildEntity_AUD").getTable(); checkTableColumns(TestTools.makeSet("child", "parent", "grandparent", "id"), TestTools.makeSet("notAudited"), explicitTransChildTable); Table implicitTransChildTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditparents.ImplicitTransitiveChildEntity_AUD").getTable(); checkTableColumns(TestTools.makeSet("child", "parent", "grandparent", "id"), TestTools.makeSet("notAudited"), implicitTransChildTable); } private void checkTableColumns(Set<String> expectedColumns, Set Other Hibernate examples (source code examples)Here is a short list of links related to this Hibernate TransitiveAuditParentsTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.