diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java new file mode 100644 index 0000000000..329119761d --- /dev/null +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/CollectionChangeNoRevisionTest.java @@ -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); + } + + +} diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Name.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Name.java new file mode 100644 index 0000000000..8d48fc1ee7 --- /dev/null +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Name.java @@ -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; + } +} diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Person.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Person.java new file mode 100644 index 0000000000..0d4c3817d7 --- /dev/null +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/norevision/Person.java @@ -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 names; + + public Person() { + names = new HashSet(); + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Set getNames() { + return names; + } + + public void setNames(Set names) { + this.names = names; + } +} diff --git a/hibernate-envers/src/test/resources/mappings/norevision/mappings.hbm.xml b/hibernate-envers/src/test/resources/mappings/norevision/mappings.hbm.xml new file mode 100644 index 0000000000..db1463c71c --- /dev/null +++ b/hibernate-envers/src/test/resources/mappings/norevision/mappings.hbm.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file