|
Hibernate example source code file (BasicSetWithNullsDelete.java)
The Hibernate BasicSetWithNullsDelete.java source code/* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.envers.test.integration.onetomany; import org.hibernate.ejb.Ejb3Configuration; import org.hibernate.envers.test.AbstractEntityTest; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.onetomany.SetRefEdEntity; import org.hibernate.envers.test.entities.onetomany.SetRefIngEntity; import org.junit.Test; import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Set; /** * @author Adam Warski (adam at warski dot org) */ public class BasicSetWithNullsDelete extends AbstractEntityTest { private Integer ed1_id; private Integer ed2_id; private Integer ing1_id; private Integer ing2_id; private Integer ing3_id; private Integer ing4_id; public void configure(Ejb3Configuration cfg) { cfg.addAnnotatedClass(SetRefEdEntity.class); cfg.addAnnotatedClass(SetRefIngEntity.class); } @Test @Priority(10) public void initData() { EntityManager em = getEntityManager(); SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1"); SetRefEdEntity ed2 = new SetRefEdEntity(2, "data_ed_2"); SetRefIngEntity ing1 = new SetRefIngEntity(3, "data_ing_1", ed1); SetRefIngEntity ing2 = new SetRefIngEntity(4, "data_ing_2", ed1); SetRefIngEntity ing3 = new SetRefIngEntity(5, "data_ing_3", ed1); SetRefIngEntity ing4 = new SetRefIngEntity(6, "data_ing_4", ed1); // Revision 1 em.getTransaction().begin(); em.persist(ed1); em.persist(ed2); em.persist(ing1); em.persist(ing2); em.persist(ing3); em.persist(ing4); em.getTransaction().commit(); // Revision 2 em.getTransaction().begin(); ing1 = em.find(SetRefIngEntity.class, ing1.getId()); ing1.setReference(null); em.getTransaction().commit(); // Revision 3 em.getTransaction().begin(); ing2 = em.find(SetRefIngEntity.class, ing2.getId()); em.remove(ing2); em.getTransaction().commit(); // Revision 4 em.getTransaction().begin(); ing3 = em.find(SetRefIngEntity.class, ing3.getId()); ed2 = em.find(SetRefEdEntity.class, ed2.getId()); ing3.setReference(ed2); em.getTransaction().commit(); // Revision 5 em.getTransaction().begin(); ing4 = em.find(SetRefIngEntity.class, ing4.getId()); ed1 = em.find(SetRefEdEntity.class, ed1.getId()); em.remove(ed1); ing4.setReference(null); em.getTransaction().commit(); // ed1_id = ed1.getId(); ed2_id = ed2.getId(); ing1_id = ing1.getId(); ing2_id = ing2.getId(); ing3_id = ing3.getId(); ing4_id = ing4.getId(); } @Test public void testRevisionsCounts() { assert Arrays.asList(1, 2, 3, 4, 5).equals(getAuditReader().getRevisions(SetRefEdEntity.class, ed1_id)); assert Arrays.asList(1, 4).equals(getAuditReader().getRevisions(SetRefEdEntity.class, ed2_id)); assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(SetRefIngEntity.class, ing1_id)); assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(SetRefIngEntity.class, ing2_id)); assert Arrays.asList(1, 4).equals(getAuditReader().getRevisions(SetRefIngEntity.class, ing3_id)); assert Arrays.asList(1, 5).equals(getAuditReader().getRevisions(SetRefIngEntity.class, ing4_id)); } private <T> Set Other Hibernate examples (source code examples)Here is a short list of links related to this Hibernate BasicSetWithNullsDelete.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.