[hibernate-commits] Hibernate SVN: r15912 - in core/trunk/envers/src: main/java/org/hibernate/envers/synchronization/work and 3 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Feb 6 18:10:40 EST 2009


Author: adamw
Date: 2009-02-06 18:10:40 -0500 (Fri, 06 Feb 2009)
New Revision: 15912

Added:
   core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/
   core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/AbstractContainedEntity.java
   core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/AbstractSetEntity.java
   core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/ContainedEntity.java
   core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/SetEntity.java
   core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/UnidirectionalDoubleAbstract.java
Modified:
   core/trunk/envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java
   core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java
   core/trunk/envers/src/test/resources/testng.xml
Log:
HHH-3741: fix and testcase; properly computing the referencing property name in a unidirectional collection

Modified: core/trunk/envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java	2009-02-06 12:20:43 UTC (rev 15911)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java	2009-02-06 23:10:40 UTC (rev 15912)
@@ -57,6 +57,7 @@
 import org.hibernate.event.PreCollectionUpdateEvent;
 import org.hibernate.event.PreCollectionUpdateEventListener;
 import org.hibernate.persister.entity.EntityPersister;
+import org.hibernate.persister.collection.AbstractCollectionPersister;
 import org.hibernate.proxy.HibernateProxy;
 
 /**
@@ -206,7 +207,7 @@
             AuditSync verSync = verCfg.getSyncManager().get(event.getSession());
 
             PersistentCollectionChangeWorkUnit workUnit = new PersistentCollectionChangeWorkUnit(entityName, verCfg,
-                    newColl, collectionEntry.getRole(), oldColl, event.getAffectedOwnerIdOrNull());
+                    newColl, collectionEntry, oldColl, event.getAffectedOwnerIdOrNull());
             verSync.addWorkUnit(workUnit);
 
             if (workUnit.containsWork()) {

Modified: core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java	2009-02-06 12:20:43 UTC (rev 15911)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java	2009-02-06 23:10:40 UTC (rev 15912)
@@ -32,6 +32,8 @@
 import org.hibernate.envers.entities.mapper.PersistentCollectionChangeData;
 
 import org.hibernate.Session;
+import org.hibernate.persister.collection.AbstractCollectionPersister;
+import org.hibernate.engine.CollectionEntry;
 import org.hibernate.collection.PersistentCollection;
 
 /**
@@ -42,11 +44,12 @@
     private final String referencingPropertyName;
 
     public PersistentCollectionChangeWorkUnit(String entityName, AuditConfiguration verCfg,
-                                              PersistentCollection collection, String role,
+                                              PersistentCollection collection, CollectionEntry collectionEntry,
                                               Serializable snapshot, Serializable id) {
         super(entityName, verCfg, null);
 
-        referencingPropertyName = role.substring(entityName.length() + 1);
+		String ownerEntityName = ((AbstractCollectionPersister) collectionEntry.getLoadedPersister()).getOwnerEntityName();
+		referencingPropertyName = collectionEntry.getRole().substring(ownerEntityName.length() + 1);
 
         collectionChanges = verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
                 .mapCollectionChanges(referencingPropertyName, collection, snapshot, id);

Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/AbstractContainedEntity.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/AbstractContainedEntity.java	                        (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/AbstractContainedEntity.java	2009-02-06 23:10:40 UTC (rev 15912)
@@ -0,0 +1,73 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.joined.relation.unidirectional;
+
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.InheritanceType;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+ at Entity
+ at Audited
+ at Inheritance(strategy = InheritanceType.JOINED)
+public abstract class AbstractContainedEntity {
+	@Id
+	@GeneratedValue
+	private Long id;
+	
+    public AbstractContainedEntity() {
+    }
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	@Override
+	public boolean equals(Object o) {
+		if (this == o) return true;
+		if (!(o instanceof AbstractContainedEntity)) return false;
+
+		AbstractContainedEntity that = (AbstractContainedEntity) o;
+
+		if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+		return true;
+	}
+
+	@Override
+	public int hashCode() {
+		return id != null ? id.hashCode() : 0;
+	}
+}
\ No newline at end of file

Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/AbstractSetEntity.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/AbstractSetEntity.java	                        (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/AbstractSetEntity.java	2009-02-06 23:10:40 UTC (rev 15912)
@@ -0,0 +1,71 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.joined.relation.unidirectional;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.OneToMany;
+
+import org.hibernate.envers.Audited;
+
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+ at Entity
+ at Inheritance(strategy = InheritanceType.JOINED)
+ at Audited
+public abstract class AbstractSetEntity {
+    @Id
+	@GeneratedValue
+    private Integer id;
+
+    @OneToMany
+    private Set<AbstractContainedEntity> entities = new HashSet<AbstractContainedEntity>();
+
+    public AbstractSetEntity() {
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+	public Set<AbstractContainedEntity> getEntities() {
+		return entities;
+	}
+
+	public void setEntities(Set<AbstractContainedEntity> entities) {
+		this.entities = entities;
+	}
+}
\ No newline at end of file

Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/ContainedEntity.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/ContainedEntity.java	                        (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/ContainedEntity.java	2009-02-06 23:10:40 UTC (rev 15912)
@@ -0,0 +1,37 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.joined.relation.unidirectional;
+
+import javax.persistence.Entity;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+ at Entity
+ at Audited
+public class ContainedEntity extends AbstractContainedEntity {	
+}
\ No newline at end of file

Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/SetEntity.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/SetEntity.java	                        (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/SetEntity.java	2009-02-06 23:10:40 UTC (rev 15912)
@@ -0,0 +1,37 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.joined.relation.unidirectional;
+
+import javax.persistence.Entity;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+ at Entity
+ at Audited
+public class SetEntity extends AbstractSetEntity {
+}
\ No newline at end of file

Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/UnidirectionalDoubleAbstract.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/UnidirectionalDoubleAbstract.java	                        (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/relation/unidirectional/UnidirectionalDoubleAbstract.java	2009-02-06 23:10:40 UTC (rev 15912)
@@ -0,0 +1,87 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.joined.relation.unidirectional;
+
+import javax.persistence.EntityManager;
+
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ejb.Ejb3Configuration;
+
+import java.util.Arrays;
+import java.util.Set;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class UnidirectionalDoubleAbstract extends AbstractEntityTest {
+	private Long cce1_id;
+	private Integer cse1_id;
+
+    public void configure(Ejb3Configuration cfg) {
+        cfg.addAnnotatedClass(AbstractContainedEntity.class);
+        cfg.addAnnotatedClass(AbstractSetEntity.class);
+        cfg.addAnnotatedClass(ContainedEntity.class);
+		cfg.addAnnotatedClass(SetEntity.class);
+    }
+
+    @BeforeClass(dependsOnMethods = "init")
+    public void initData() {
+        EntityManager em = getEntityManager();
+
+        // Rev 1
+        em.getTransaction().begin();
+
+        ContainedEntity cce1 = new ContainedEntity();
+		em.persist(cce1);
+
+		SetEntity cse1 = new SetEntity();
+		cse1.getEntities().add(cce1);
+		em.persist(cse1);
+
+        em.getTransaction().commit();
+
+		cce1_id = cce1.getId();
+		cse1_id = cse1.getId();
+    }
+
+	@Test
+    public void testRevisionsCounts() {
+        assert Arrays.asList(1).equals(getAuditReader().getRevisions(ContainedEntity.class, cce1_id));
+        assert Arrays.asList(1).equals(getAuditReader().getRevisions(SetEntity.class, cse1_id));
+    }
+
+    @Test
+    public void testHistoryOfReferencedCollection() {
+		ContainedEntity cce1 = getEntityManager().find(ContainedEntity.class, cce1_id);
+
+		Set<AbstractContainedEntity> entities = getAuditReader().find(SetEntity.class, cse1_id, 1).getEntities();
+        assert entities.size() == 1;
+		assert entities.iterator().next() instanceof ContainedEntity;
+		assert entities.contains(cce1);
+    }
+}
\ No newline at end of file

Modified: core/trunk/envers/src/test/resources/testng.xml
===================================================================
--- core/trunk/envers/src/test/resources/testng.xml	2009-02-06 12:20:43 UTC (rev 15911)
+++ core/trunk/envers/src/test/resources/testng.xml	2009-02-06 23:10:40 UTC (rev 15912)
@@ -19,6 +19,7 @@
             <package name="org.hibernate.envers.test.integration.inheritance.joined.emptychild" />
             <package name="org.hibernate.envers.test.integration.inheritance.joined.notownedrelation" />
             <package name="org.hibernate.envers.test.integration.inheritance.joined.relation" />
+            <package name="org.hibernate.envers.test.integration.inheritance.joined.relation.unidirectional" />
             <package name="org.hibernate.envers.test.integration.inheritance.single" />
             <package name="org.hibernate.envers.test.integration.inheritance.single.childrelation" />
             <package name="org.hibernate.envers.test.integration.inheritance.single.notownedrelation" />




More information about the hibernate-commits mailing list