HHH-4648 - Test case
This commit is contained in:
parent
310c0441bb
commit
5b635d2c44
|
@ -1,5 +1,5 @@
|
||||||
package org.hibernate.envers.test.integration.entityNames.singleAssociatedAudited;
|
package org.hibernate.envers.test.integration.entityNames.singleAssociatedAudited;
|
||||||
import org.hibernate.envers.Audited;
|
import org.hibernate.envers.Audited;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hernán Chanfreau
|
* @author Hernán Chanfreau
|
||||||
|
@ -15,12 +15,14 @@ public class Car {
|
||||||
|
|
||||||
private Person owner;
|
private Person owner;
|
||||||
|
|
||||||
|
private Person driver;
|
||||||
|
|
||||||
public Car() { }
|
public Car() { }
|
||||||
|
|
||||||
public Car(int number, Person owner) {
|
public Car(int number, Person owner, Person driver) {
|
||||||
this.number = number;
|
this.number = number;
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
|
this.driver = driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,6 +50,11 @@ public class Car {
|
||||||
this.number = number;
|
this.number = number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Person getDriver() {
|
||||||
|
return driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDriver(Person driver) {
|
||||||
|
this.driver = driver;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,8 +45,8 @@ public class ReadEntityAssociatedAuditedTest extends AbstractOneSessionTest{
|
||||||
Person pers1 = new Person("Hernan", 15);
|
Person pers1 = new Person("Hernan", 15);
|
||||||
Person pers2 = new Person("Leandro", 19);
|
Person pers2 = new Person("Leandro", 19);
|
||||||
|
|
||||||
Car car1 = new Car(1, pers1);
|
Car car1 = new Car(1, pers1, null);
|
||||||
Car car2 = new Car(2, pers2);
|
Car car2 = new Car(2, pers2, null);
|
||||||
|
|
||||||
//REV 1
|
//REV 1
|
||||||
getSession().getTransaction().begin();
|
getSession().getTransaction().begin();
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
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, null);
|
||||||
|
getSession().persist("Personaje", owner);
|
||||||
|
getSession().persist("Driveraje", driver);
|
||||||
|
car.setDriver(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 references. */
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||||
<hibernate-mapping>
|
<hibernate-mapping>
|
||||||
|
|
||||||
<class name="org.hibernate.envers.test.integration.entityNames.singleAssociatedAudited.Person" entity-name="Personaje">
|
<class name="org.hibernate.envers.test.integration.entityNames.singleAssociatedAudited.Person" entity-name="Personaje" table="OWNERS">
|
||||||
|
|
||||||
<id name="id" column="ID_person" type="long" >
|
<id name="id" column="ID_person" type="long" >
|
||||||
<generator class="native" />
|
<generator class="native" />
|
||||||
|
@ -14,6 +14,20 @@
|
||||||
<property name="age" type="int" column="AGE"/>
|
<property name="age" type="int" column="AGE"/>
|
||||||
|
|
||||||
</class>
|
</class>
|
||||||
|
|
||||||
|
<!-- Deliberately use the same domain object and map it to a different database table. See issue HHH-4648. -->
|
||||||
|
<class name="org.hibernate.envers.test.integration.entityNames.singleAssociatedAudited.Person" entity-name="Driveraje" table="DRIVERS">
|
||||||
|
|
||||||
|
<id name="id" column="ID_person" type="long" >
|
||||||
|
<generator class="native" />
|
||||||
|
</id>
|
||||||
|
|
||||||
|
<property name="name" type="string" length="255"
|
||||||
|
column="NAME" not-null="true" />
|
||||||
|
|
||||||
|
<property name="age" type="int" column="AGE"/>
|
||||||
|
|
||||||
|
</class>
|
||||||
|
|
||||||
<class name="org.hibernate.envers.test.integration.entityNames.singleAssociatedAudited.Car" >
|
<class name="org.hibernate.envers.test.integration.entityNames.singleAssociatedAudited.Car" >
|
||||||
|
|
||||||
|
@ -24,7 +38,9 @@
|
||||||
<property name="number" type="int" column="int" not-null="true" />
|
<property name="number" type="int" column="int" not-null="true" />
|
||||||
|
|
||||||
<many-to-one name="owner" entity-name="Personaje"/>
|
<many-to-one name="owner" entity-name="Personaje"/>
|
||||||
|
|
||||||
|
<many-to-one name="driver" entity-name="Driveraje"/>
|
||||||
|
|
||||||
</class>
|
</class>
|
||||||
|
|
||||||
</hibernate-mapping>
|
</hibernate-mapping>
|
||||||
|
|
Loading…
Reference in New Issue