Test for creating revision on collection change
This commit is contained in:
parent
2667bb4d72
commit
387faed855
|
@ -0,0 +1,59 @@
|
|||
package org.hibernate.envers.test.integration.collection.norevision;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.hibernate.envers.test.AbstractSessionTest;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Optional;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
public class CollectionChangeNoRevisionTest extends AbstractSessionTest {
|
||||
|
||||
private Integer personId;
|
||||
|
||||
@Override
|
||||
protected void initMappings() throws MappingException, URISyntaxException {
|
||||
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/norevision/mappings.hbm.xml");
|
||||
config.addFile(new File(url.toURI()));
|
||||
config.setProperty("org.hibernate.envers.revision_on_collection_change", "false");
|
||||
}
|
||||
|
||||
@BeforeMethod(firstTimeOnly = true)
|
||||
public void initData() {
|
||||
newSessionFactory();
|
||||
Person p = new Person();
|
||||
Name n = new Name();
|
||||
n.setName("name1");
|
||||
p.getNames().add(n);
|
||||
Transaction transaction = getSession().beginTransaction();
|
||||
getSession().saveOrUpdate(p);
|
||||
transaction.commit();
|
||||
personId = p.getId();
|
||||
System.err.print(p);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersonRevisionCount() {
|
||||
Person p = (Person) getSession().createCriteria(Person.class).add(Restrictions.idEq(personId)).uniqueResult();
|
||||
Name n2 = new Name();
|
||||
n2.setName("name2");
|
||||
p.getNames().add(n2);
|
||||
Transaction transaction = getSession().beginTransaction();
|
||||
getSession().saveOrUpdate(p);
|
||||
transaction.commit();
|
||||
int size = getAuditReader().getRevisions(Person.class, personId).size();
|
||||
System.out.println(size);
|
||||
Assert.assertEquals(config.getProperty("org.hibernate.envers.revision_on_collection_change"), "false");
|
||||
Assert.assertEquals(size, 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package org.hibernate.envers.test.integration.collection.norevision;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Audited
|
||||
public class Name implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Person person;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Person getPerson() {
|
||||
return person;
|
||||
}
|
||||
|
||||
public void setPerson(Person person) {
|
||||
this.person = person;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package org.hibernate.envers.test.integration.collection.norevision;
|
||||
|
||||
import org.hibernate.envers.AuditMappedBy;
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Audited
|
||||
public class Person implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
@AuditMappedBy(mappedBy = "person")
|
||||
private Set<Name> names;
|
||||
|
||||
public Person() {
|
||||
names = new HashSet<Name>();
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Set<Name> getNames() {
|
||||
return names;
|
||||
}
|
||||
|
||||
public void setNames(Set<Name> names) {
|
||||
this.names = names;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping>
|
||||
<class name="org.hibernate.envers.test.integration.collection.norevision.Person">
|
||||
<id name="id">
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
<set name="names" cascade="save-update">
|
||||
<key column="Person_Id"/>
|
||||
<one-to-many class="org.hibernate.envers.test.integration.collection.norevision.Name"/>
|
||||
</set>
|
||||
</class>
|
||||
<class name="org.hibernate.envers.test.integration.collection.norevision.Name">
|
||||
<id name="id">
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
<property name="name"/>
|
||||
<many-to-one name="person" class="org.hibernate.envers.test.integration.collection.norevision.Person"
|
||||
column="Person_Id" cascade="save-update"/>
|
||||
</class>
|
||||
</hibernate-mapping>
|
Loading…
Reference in New Issue