Merge branch 'master' of github.com:hibernate/hibernate-core

This commit is contained in:
Gail Badner 2010-12-09 20:35:48 -08:00
commit 64c2d4846f
7 changed files with 176 additions and 1 deletions

View File

@ -257,7 +257,9 @@ public class AuditEventListener implements PostInsertEventListener, PostUpdateEv
private void onCollectionAction(AbstractCollectionEvent event, PersistentCollection newColl, Serializable oldColl,
CollectionEntry collectionEntry) {
String entityName = event.getAffectedOwnerEntityName();
if (! verCfg.getGlobalCfg().isGenerateRevisionsForCollections()) {
return;
}
if (verCfg.getEntCfg().isVersioned(entityName)) {
AuditProcess auditProcess = verCfg.getSyncManager().get(event.getSession());

View File

@ -0,0 +1,58 @@
package org.hibernate.envers.test.integration.collection.norevision;
import org.hibernate.MappingException;
import org.hibernate.envers.test.AbstractSessionTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.net.URISyntaxException;
import java.util.List;
public abstract class AbstractCollectionChangeTest extends AbstractSessionTest {
protected Integer personId;
@Override
protected void initMappings() throws MappingException, URISyntaxException {
config.addAnnotatedClass(Person.class);
config.addAnnotatedClass(Name.class);
config.setProperty("org.hibernate.envers.revision_on_collection_change", getCollectionChangeValue());
}
protected abstract String getCollectionChangeValue();
protected abstract List<Integer> getExpectedPersonRevisions();
@BeforeClass(dependsOnMethods = "init")
public void initData() {
newSessionFactory();
// Rev 1
getSession().getTransaction().begin();
Person p = new Person();
Name n = new Name();
n.setName("name1");
p.getNames().add(n);
getSession().saveOrUpdate(p);
getSession().getTransaction().commit();
// Rev 2
getSession().getTransaction().begin();
n.setName("Changed name");
getSession().saveOrUpdate(p);
getSession().getTransaction().commit();
// Rev 3
getSession().getTransaction().begin();
Name n2 = new Name();
n2.setName("name2");
p.getNames().add(n2);
getSession().getTransaction().commit();
personId = p.getId();
}
@Test
public void testPersonRevisionCount() {
assert getAuditReader().getRevisions(Person.class, personId).equals(getExpectedPersonRevisions());
}
}

View File

@ -0,0 +1,15 @@
package org.hibernate.envers.test.integration.collection.norevision;
import java.util.Arrays;
import java.util.List;
public class CollectionChangeNoRevisionTest extends AbstractCollectionChangeTest {
protected String getCollectionChangeValue() {
return "false";
}
@Override
protected List<Integer> getExpectedPersonRevisions() {
return Arrays.asList(1);
}
}

View File

@ -0,0 +1,16 @@
package org.hibernate.envers.test.integration.collection.norevision;
import java.util.Arrays;
import java.util.List;
public class CollectionChangeRevisionTest extends AbstractCollectionChangeTest {
@Override
protected String getCollectionChangeValue() {
return "true";
}
@Override
protected List<Integer> getExpectedPersonRevisions() {
return Arrays.asList(1, 3);
}
}

View File

@ -0,0 +1,43 @@
package org.hibernate.envers.test.integration.collection.norevision;
import org.hibernate.envers.Audited;
import javax.persistence.*;
import java.io.Serializable;
@Audited
@Entity
public class Name implements Serializable {
@Id
@GeneratedValue
private Integer id;
private String name;
@ManyToOne
@JoinColumn(name = "person_id", insertable = false, updatable = false)
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;
}
}

View File

@ -0,0 +1,40 @@
package org.hibernate.envers.test.integration.collection.norevision;
import org.hibernate.envers.AuditMappedBy;
import org.hibernate.envers.Audited;
import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
@Audited
@Entity
public class Person implements Serializable {
@Id @GeneratedValue
private Integer id;
@AuditMappedBy(mappedBy = "person")
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "person_id")
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;
}
}

View File

@ -6,6 +6,7 @@
<package name="org.hibernate.envers.test.integration.cache" />
<package name="org.hibernate.envers.test.integration.collection" />
<package name="org.hibernate.envers.test.integration.collection.mapkey" />
<package name="org.hibernate.envers.test.integration.collection.norevision" />
<package name="org.hibernate.envers.test.integration.components" />
<package name="org.hibernate.envers.test.integration.components.relations" />
<package name="org.hibernate.envers.test.integration.customtype" />