alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (AbstractCollectionChangeTest.java)

This example Hibernate source code file (AbstractCollectionChangeTest.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

abstractsessiontest, changed, integer, mappingexception, name, name, net, network, override, person, person, priority, priority, test, test, urisyntaxexception, util

The Hibernate AbstractCollectionChangeTest.java source code

package org.hibernate.envers.test.integration.collection.norevision;

import org.hibernate.MappingException;
import org.hibernate.envers.test.AbstractSessionTest;
import org.hibernate.envers.test.Priority;
import org.junit.Test;

import java.net.URISyntaxException;
import java.util.List;

public abstract class AbstractCollectionChangeTest extends AbstractSessionTest {
    protected Integer personId;

    @Override
    protected void initMappings() throws MappingException, URISyntaxException {
        config.addAnnotatedClass(Person.class);
        config.addAnnotatedClass(Name.class);
        config.setProperty("org.hibernate.envers.revision_on_collection_change", getCollectionChangeValue());
    }

    protected abstract String getCollectionChangeValue();

    protected abstract List<Integer> getExpectedPersonRevisions();

    @Test
    @Priority(10)
    public void initData() {
    	newSessionFactory();

        // Rev 1
        getSession().getTransaction().begin();        
        Person p = new Person();
        Name n = new Name();
        n.setName("name1");
        p.getNames().add(n);
        getSession().saveOrUpdate(p);
        getSession().getTransaction().commit();

        // Rev 2
        getSession().getTransaction().begin();
        n.setName("Changed name");
        getSession().saveOrUpdate(p);
        getSession().getTransaction().commit();

        // Rev 3
        getSession().getTransaction().begin();
        Name n2 = new Name();
        n2.setName("name2");
        p.getNames().add(n2);
        getSession().getTransaction().commit();

        personId = p.getId();
    }

    @Test
    public void testPersonRevisionCount() {
        assert getAuditReader().getRevisions(Person.class, personId).equals(getExpectedPersonRevisions());
    }
}

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate AbstractCollectionChangeTest.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

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.