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

Hibernate example source code file (ReadWriteExpressionChange.java)

This example Hibernate source code file (ReadWriteExpressionChange.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

abstractentitytest, double, entitymanager, entitymanager, height_centimeters, height_inches, height_inches, integer, list, override, staff, staff, test, test, util

The Hibernate ReadWriteExpressionChange.java source code

package org.hibernate.envers.test.integration.readwriteexpression;

import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.envers.test.AbstractEntityTest;
import org.hibernate.envers.test.Priority;
import org.junit.Test;

import javax.persistence.EntityManager;
import java.util.List;

public class ReadWriteExpressionChange extends AbstractEntityTest {

    private static final double HEIGHT_INCHES = 73;
    private static final double HEIGHT_CENTIMETERS = HEIGHT_INCHES * 2.54d;

    private Integer id;

    @Override
    public void configure(Ejb3Configuration cfg) {
        cfg.addAnnotatedClass(Staff.class);
    }

    @Test
    @Priority(10)
    public void initData() {
        EntityManager em = getEntityManager();
        em.getTransaction().begin();
        Staff staff = new Staff(HEIGHT_INCHES, 1);
        em.persist(staff);
        em.getTransaction().commit();
        id = staff.getId();
    }

    @Test
    public void shouldRespectWriteExpression() {
        EntityManager em = getEntityManager();
        List resultList = em.createNativeQuery("select size_in_cm from t_staff_AUD where id ="+id).getResultList();
        assert 1 == resultList.size();
        Double sizeInCm = (Double) resultList.get(0);
        assert sizeInCm.equals(HEIGHT_CENTIMETERS);
    }

    @Test
    public void shouldRespectReadExpression() {
        List<Number> revisions = getAuditReader().getRevisions(Staff.class, id);
        assert 1 == revisions.size();
        Number number = revisions.get(0);
        Staff staffRev = getAuditReader().find(Staff.class, id, number);
        assert HEIGHT_INCHES == staffRev.getSizeInInches();
    }

}

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate ReadWriteExpressionChange.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.