Merge branch '3.6' of https://github.com/rsvato/hibernate-core into 3.6
This commit is contained in:
commit
0168ffa83c
|
@ -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());
|
||||
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
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;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CollectionChangeNoRevisionTest extends AbstractSessionTest {
|
||||
|
||||
protected static final int EXPECTED_PERSON_REVISION_COUNT = 1;
|
||||
protected static final String CREATE_REVISION_ON_COLLECTION_CHANGE = "false";
|
||||
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 String getCollectionChangeValue() {
|
||||
return CREATE_REVISION_ON_COLLECTION_CHANGE;
|
||||
}
|
||||
|
||||
@BeforeClass(dependsOnMethods = "init")
|
||||
public void initData() {
|
||||
newSessionFactory();
|
||||
Person p = new Person();
|
||||
Name n = new Name();
|
||||
n.setName("name1");
|
||||
p.getNames().add(n);
|
||||
getSession().getTransaction().begin();
|
||||
getSession().saveOrUpdate(p);
|
||||
getSession().getTransaction().commit();
|
||||
personId = p.getId();
|
||||
getSession().getTransaction().begin();
|
||||
n.setName("Changed name");
|
||||
getSession().saveOrUpdate(p);
|
||||
getSession().getTransaction().commit();
|
||||
getSession().getTransaction().begin();
|
||||
Name n2 = new Name();
|
||||
n2.setName("name2");
|
||||
p.getNames().add(n2);
|
||||
getSession().getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersonRevisionCount() {
|
||||
int sizePerson = getAuditReader().getRevisions(Person.class, personId).size();
|
||||
assert sizePerson == getExpectedPersonRevisionCount();
|
||||
}
|
||||
|
||||
protected int getExpectedPersonRevisionCount() {
|
||||
return EXPECTED_PERSON_REVISION_COUNT;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package org.hibernate.envers.test.integration.collection.norevision;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
public class CollectionChangeRevisionTest extends CollectionChangeNoRevisionTest {
|
||||
|
||||
protected static final int PERSON_COUNT_NEW_REVISION_ON_COLLECTION = 2;
|
||||
protected static final String NEW_REVISION_ON_COLLECTION = "true";
|
||||
|
||||
@Override
|
||||
protected void initMappings() throws MappingException, URISyntaxException {
|
||||
super.initMappings();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getExpectedPersonRevisionCount() {
|
||||
return PERSON_COUNT_NEW_REVISION_ON_COLLECTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCollectionChangeValue() {
|
||||
return NEW_REVISION_ON_COLLECTION;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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" />
|
||||
|
|
Loading…
Reference in New Issue