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

Hibernate example source code file (SingleDomainObjectToMultipleTablesTest.java)

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

abstractonesessiontest, car, car, driveraje, io, kinga, kinga, lukasz, lukasz, mappingexception, net, network, person, person, personaje, test, testforissue

The Hibernate SingleDomainObjectToMultipleTablesTest.java source code

package org.hibernate.envers.test.integration.entityNames.singleAssociatedAudited;

import org.hibernate.MappingException;
import org.hibernate.envers.test.AbstractOneSessionTest;
import org.hibernate.envers.test.Priority;
import org.hibernate.testing.TestForIssue;
import org.junit.Assert;
import org.junit.Test;

import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;

/**
 * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
 */
public class SingleDomainObjectToMultipleTablesTest extends AbstractOneSessionTest {
    private long carId = 0;
    private long ownerId = 0;
    private long driverId = 0;

    protected void initMappings() throws MappingException, URISyntaxException {
        URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/singleAssociatedAudited/mappings.hbm.xml");
        config.addFile(new File(url.toURI()));
    }


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

        //REV 1
        getSession().getTransaction().begin();
        Person owner = new Person("Lukasz", 25);
        Person driver = new Person("Kinga", 24);
        Car car = new Car(1, owner, driver);
        getSession().persist("Personaje", owner);
        getSession().persist("Driveraje", driver);
        getSession().persist(car);
        getSession().getTransaction().commit();
        
        carId = car.getId();
        ownerId = owner.getId();
        driverId = driver.getId();
    }

    @Test
    @TestForIssue(jiraKey="HHH-4648")
    public void testSingleDomainObjectToMultipleTablesMapping() {
        Car carVer1 = getAuditReader().find(Car.class, carId, 1);
        Person ownerVer1 = getAuditReader().find(Person.class, "Personaje", ownerId, 1);
        Person driverVer1 = getAuditReader().find(Person.class, "Driveraje", driverId, 1);

        /* Check ids. */
        Assert.assertEquals(ownerVer1.getId(), carVer1.getOwner().getId());
        Assert.assertEquals(driverVer1.getId(), carVer1.getDriver().getId());

        /* Check object properties. */
        Assert.assertEquals("Lukasz", ownerVer1.getName());
        Assert.assertEquals("Kinga", driverVer1.getName());
        Assert.assertEquals(1, carVer1.getNumber());
    }
}

Other Hibernate examples (source code examples)

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