Ignore collection changes if no revision on collection change is set
This commit is contained in:
parent
fd54b2df56
commit
e831e29435
|
@ -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,27 @@
|
|||
package org.hibernate.envers.test.integration.collection.norevision;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
public class CollectionChangRevisionTest 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;
|
||||
}
|
||||
}
|
|
@ -13,16 +13,26 @@ 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 {
|
||||
|
||||
private Integer personId;
|
||||
protected static final int EXPECTED_PERSON_REVISION_COUNT = 1;
|
||||
protected static final int EXPECTED_NAME_REVISION_COUNT = 1;
|
||||
protected static final String CREATE_REVISION_ON_COLLECTION_CHANGE = "false";
|
||||
protected Integer personId;
|
||||
protected List<Integer> namesId = new ArrayList<Integer>();
|
||||
|
||||
@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");
|
||||
config.setProperty("org.hibernate.envers.revision_on_collection_change", getCollectionChangeValue());
|
||||
}
|
||||
|
||||
protected String getCollectionChangeValue() {
|
||||
return CREATE_REVISION_ON_COLLECTION_CHANGE;
|
||||
}
|
||||
|
||||
@BeforeMethod(firstTimeOnly = true)
|
||||
|
@ -36,7 +46,7 @@ public class CollectionChangeNoRevisionTest extends AbstractSessionTest {
|
|||
getSession().saveOrUpdate(p);
|
||||
transaction.commit();
|
||||
personId = p.getId();
|
||||
System.err.print(p);
|
||||
namesId.add(n.getId());
|
||||
|
||||
}
|
||||
|
||||
|
@ -49,10 +59,18 @@ public class CollectionChangeNoRevisionTest extends AbstractSessionTest {
|
|||
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);
|
||||
namesId.add(n2.getId());
|
||||
int sizePerson = getAuditReader().getRevisions(Person.class, personId).size();
|
||||
Assert.assertEquals(config.getProperty("org.hibernate.envers.revision_on_collection_change"), getCollectionChangeValue());
|
||||
Assert.assertEquals(sizePerson, getExpectedPersonRevisionCount());
|
||||
for (Integer id : namesId) {
|
||||
int sizeName = getAuditReader().getRevisions(Name.class, id).size();
|
||||
Assert.assertEquals(sizeName, EXPECTED_NAME_REVISION_COUNT);
|
||||
}
|
||||
}
|
||||
|
||||
protected int getExpectedPersonRevisionCount() {
|
||||
return EXPECTED_PERSON_REVISION_COUNT;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,6 +16,6 @@
|
|||
</id>
|
||||
<property name="name"/>
|
||||
<many-to-one name="person" class="org.hibernate.envers.test.integration.collection.norevision.Person"
|
||||
column="Person_Id" cascade="save-update"/>
|
||||
column="Person_Id" cascade="save-update" update="false" insert="false"/>
|
||||
</class>
|
||||
</hibernate-mapping>
|
|
@ -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