Author: adamw
Date: 2009-06-05 11:30:57 -0400 (Fri, 05 Jun 2009)
New Revision: 16713
Added:
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildNullAuditing.java
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/SinglePropertyMapper.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/event/AuditEventListener.java
Log:
svn merge -r 16502:16710
https://svn.jboss.org/repos/hibernate/core/trunk/envers .
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-06-05
15:27:59 UTC (rev 16712)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-06-05
15:30:57 UTC (rev 16713)
@@ -164,6 +164,19 @@
}
}
+ private boolean checkPropertiesAudited(Iterator<Property> properties,
ClassAuditingData auditingData) {
+ while (properties.hasNext()) {
+ Property property = properties.next();
+ String propertyName = property.getName();
+ PropertyAuditingData propertyAuditingData =
auditingData.getPropertyAuditingData(propertyName);
+ if (propertyAuditingData == null) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
@SuppressWarnings({"unchecked"})
private void createJoins(PersistentClass pc, Element parent, ClassAuditingData
auditingData) {
Iterator<Join> joins = pc.getJoinIterator();
@@ -174,6 +187,11 @@
while (joins.hasNext()) {
Join join = joins.next();
+ // Checking if all of the join properties are audited
+ if (!checkPropertiesAudited(join.getPropertyIterator(), auditingData)) {
+ continue;
+ }
+
// Determining the table name. If there is no entry in the dictionary, just
constructing the table name
// as if it was an entity (by appending/prepending configured strings).
String originalTableName = join.getTable().getName();
@@ -210,8 +228,10 @@
Join join = joins.next();
Element joinElement = entitiesJoins.get(entityName).get(join);
- addProperties(joinElement, join.getPropertyIterator(), currentMapper,
auditingData, entityName,
- xmlMappingData, firstPass);
+ if (joinElement != null) {
+ addProperties(joinElement, join.getPropertyIterator(), currentMapper,
auditingData, entityName,
+ xmlMappingData, firstPass);
+ }
}
}
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/SinglePropertyMapper.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/SinglePropertyMapper.java 2009-06-05
15:27:59 UTC (rev 16712)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/SinglePropertyMapper.java 2009-06-05
15:30:57 UTC (rev 16713)
@@ -78,13 +78,17 @@
}
private boolean isPrimitive(Setter setter, PropertyData propertyData, Class<?>
cls) {
+ if (cls == null) {
+ throw new HibernateException("No field found for property: " +
propertyData.getName());
+ }
+
if (setter instanceof DirectPropertyAccessor.DirectSetter) {
// In a direct setter, getMethod() returns null
// Trying to look up the field
try {
return cls.getDeclaredField(propertyData.getBeanName()).getType().isPrimitive();
} catch (NoSuchFieldException e) {
- throw new HibernateException(e);
+ return isPrimitive(setter, propertyData, cls.getSuperclass());
}
} else {
return setter.getMethod().getParameterTypes()[0].isPrimitive();
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/event/AuditEventListener.java
===================================================================
---
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/event/AuditEventListener.java 2009-06-05
15:27:59 UTC (rev 16712)
+++
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/event/AuditEventListener.java 2009-06-05
15:30:57 UTC (rev 16713)
@@ -243,7 +243,7 @@
public void onPreRemoveCollection(PreCollectionRemoveEvent event) {
CollectionEntry collectionEntry = getCollectionEntry(event);
- if (!collectionEntry.getLoadedPersister().isInverse()) {
+ if (collectionEntry != null &&
!collectionEntry.getLoadedPersister().isInverse()) {
onCollectionAction(event, null, collectionEntry.getSnapshot(),
collectionEntry);
}
}
Copied:
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildNullAuditing.java
(from rev 16710,
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildNullAuditing.java)
===================================================================
---
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildNullAuditing.java
(rev 0)
+++
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildNullAuditing.java 2009-06-05
15:30:57 UTC (rev 16713)
@@ -0,0 +1,94 @@
+/*
+ * 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;
+
+import java.util.Arrays;
+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;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ChildNullAuditing extends AbstractEntityTest {
+ private Integer id1;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(ChildEntity.class);
+ cfg.addAnnotatedClass(ParentEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ id1 = 1;
+
+ // Rev 1
+ em.getTransaction().begin();
+ ChildEntity ce = new ChildEntity(id1, "x", null);
+ em.persist(ce);
+ em.getTransaction().commit();
+
+ // Rev 2
+ em.getTransaction().begin();
+ ce = em.find(ChildEntity.class, id1);
+ ce.setData(null);
+ ce.setNumber(2l);
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1,
2).equals(getAuditReader().getRevisions(ChildEntity.class, id1));
+ }
+
+ @Test
+ public void testHistoryOfChildId1() {
+ ChildEntity ver1 = new ChildEntity(id1, "x", null);
+ ChildEntity ver2 = new ChildEntity(id1, null, 2l);
+
+ assert getAuditReader().find(ChildEntity.class, id1, 1).equals(ver1);
+ assert getAuditReader().find(ChildEntity.class, id1, 2).equals(ver2);
+
+ assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1);
+ assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2);
+ }
+
+ @Test
+ public void testPolymorphicQuery() {
+ ChildEntity childVer1 = new ChildEntity(id1, "x", null);
+
+ assert getAuditReader().createQuery().forEntitiesAtRevision(ChildEntity.class,
1).getSingleResult()
+ .equals(childVer1);
+
+ assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class,
1).getSingleResult()
+ .equals(childVer1);
+ }
+}
\ No newline at end of file