diff --git a/documentation/src/main/docbook/devguide/en-US/Envers.xml b/documentation/src/main/docbook/devguide/en-US/Envers.xml index 24be2edb8e..32a3b129ea 100644 --- a/documentation/src/main/docbook/devguide/en-US/Envers.xml +++ b/documentation/src/main/docbook/devguide/en-US/Envers.xml @@ -313,9 +313,10 @@ If you'd like to audit properties of a superclass of an entity, which are not explicitly audited (which - don't have the @Audited annotation on any properties or on the class), - you can list the superclasses in the auditParents attribute of the - @Audited annotation. + don't have the @Audited annotation on any properties or on the class), you can list the + superclasses in the auditParents attribute of the @Audited + annotation. Please note that auditParents feature has been deprecated. Use + @AuditOverride(forClass = SomeEntity.class, isAudited = true/false) instead. diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/AuditOverride.java b/hibernate-envers/src/main/java/org/hibernate/envers/AuditOverride.java index a76600be8a..4af1993842 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/AuditOverride.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/AuditOverride.java @@ -26,10 +26,11 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; public @interface AuditOverride { /** - * @return Required Name of the field (or property) whose mapping - * is being overridden. + * @return Name of the field (or property) whose mapping is being overridden. Allows empty value if + * {@link AuditOverride} is used to change auditing behavior of all attributes inherited from + * {@link MappedSuperclass} type. */ - String name(); + String name() default ""; /** * @return Indicates if the field (or property) is audited; defaults to {@code true}. @@ -47,5 +48,5 @@ public @interface AuditOverride { * {@link AuditOverride} is used to change auditing behavior of attributes inherited from {@link MappedSuperclass} * type. */ - Class relatedClass() default void.class; + Class forClass() default void.class; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/Audited.java b/hibernate-envers/src/main/java/org/hibernate/envers/Audited.java index 080be2c956..0a75575eb0 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/Audited.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/Audited.java @@ -55,6 +55,8 @@ public @interface Audited { * * If a parent type lists any of its parent types using this attribute, all properties in the specified classes * will also be audited. + * + * @deprecated Use {@code @AuditOverride(forClass=SomeEntity.class)} instead. */ Class[] auditParents() default {}; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java index b80bca56af..2792b1ae60 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java @@ -2,7 +2,6 @@ package org.hibernate.envers.configuration.metadata.reader; import java.lang.annotation.Annotation; import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -25,6 +24,7 @@ import org.hibernate.envers.NotAudited; import org.hibernate.envers.RelationTargetAuditMode; import org.hibernate.envers.configuration.GlobalConfiguration; import org.hibernate.envers.tools.MappingTools; +import org.hibernate.envers.tools.StringTools; import org.hibernate.envers.tools.Tools; import org.hibernate.mapping.Component; import org.hibernate.mapping.Property; @@ -60,6 +60,9 @@ public class AuditedPropertiesReader { private final Set overriddenAuditedProperties; private final Set overriddenNotAuditedProperties; + private final Set overriddenAuditedClasses; + private final Set overriddenNotAuditedClasses; + public AuditedPropertiesReader(ModificationStore defaultStore, PersistentPropertiesSource persistentPropertiesSource, AuditedPropertiesHolder auditedPropertiesHolder, @@ -79,36 +82,51 @@ public class AuditedPropertiesReader { overriddenAuditedProperties = newHashSet(); overriddenNotAuditedProperties = newHashSet(); + + overriddenAuditedClasses = newHashSet(); + overriddenNotAuditedClasses = newHashSet(); } public void read() { // First reading the access types for the persistent properties. readPersistentPropertiesAccess(); - // Retrieve classes that are explicitly marked for auditing process by any superclass of currently mapped - // entity or itself. + // Retrieve classes and properties that are explicitly marked for auditing process by any superclass + // of currently mapped entity or itself. XClass clazz = persistentPropertiesSource.getXClass(); - Set declaredAuditedSuperclasses = new HashSet(); - doGetDeclaredAuditedSuperclasses(clazz, declaredAuditedSuperclasses); - doReadOverrideAuditedProperties(clazz); + doReadOverrideAudited(clazz); // Adding all properties from the given class. - addPropertiesFromClass(clazz, declaredAuditedSuperclasses); + addPropertiesFromClass(clazz); } /** - * Recursively constructs sets of audited and not audited properties which behavior has been overridden + * Recursively constructs sets of audited and not audited properties and classes which behavior has been overridden * using @AuditOverride annotation. * @param clazz Class that is being processed. Currently mapped entity shall be passed during first invocation. */ - private void doReadOverrideAuditedProperties(XClass clazz) { + private void doReadOverrideAudited(XClass clazz) { + /* TODO: Code to remove with @Audited.auditParents - start. */ + Audited allClassAudited = clazz.getAnnotation(Audited.class); + if (allClassAudited != null && allClassAudited.auditParents().length > 0) { + for (Class c : allClassAudited.auditParents()) { + XClass parentClass = reflectionManager.toXClass(c); + checkSuperclass(clazz, parentClass); + if (!overriddenNotAuditedClasses.contains(parentClass)) { + // If the class has not been marked as not audited by the subclass. + overriddenAuditedClasses.add(parentClass); + } + } + } + /* TODO: Code to remove with @Audited.auditParents - finish. */ List auditOverrides = computeAuditOverrides(clazz); for (AuditOverride auditOverride : auditOverrides) { - if (auditOverride.relatedClass() != void.class) { - XClass overrideClass = reflectionManager.toXClass(auditOverride.relatedClass()); + if (auditOverride.forClass() != void.class) { + XClass overrideClass = reflectionManager.toXClass(auditOverride.forClass()); checkSuperclass(clazz, overrideClass); String propertyName = auditOverride.name(); - if (propertyName != null) { + if (!StringTools.isEmpty(propertyName)) { + // Overridden @Audited annotation on property level. XProperty property = getProperty(overrideClass, propertyName); if (auditOverride.isAudited()) { if (!overriddenNotAuditedProperties.contains(property)) { @@ -121,12 +139,25 @@ public class AuditedPropertiesReader { overriddenNotAuditedProperties.add(property); } } + } else { + // Overridden @Audited annotation on class level. + if (auditOverride.isAudited()) { + if (!overriddenNotAuditedClasses.contains(overrideClass)) { + // If the class has not been marked as not audited by the subclass. + overriddenAuditedClasses.add(overrideClass); + } + } else { + if (!overriddenAuditedClasses.contains(overrideClass)) { + // If the class has not been marked as audited by the subclass. + overriddenNotAuditedClasses.add(overrideClass); + } + } } } } XClass superclass = clazz.getSuperclass(); if (!clazz.isInterface() && !Object.class.getName().equals(superclass.getName())) { - doReadOverrideAuditedProperties(superclass); + doReadOverrideAudited(superclass); } } @@ -148,28 +179,6 @@ public class AuditedPropertiesReader { return Collections.EMPTY_LIST; } - /** - * Recursively constructs a set of classes that have been declared for auditing process. - * @param clazz Class that is being processed. Currently mapped entity shall be passed during first invocation. - * @param declaredAuditedSuperclasses Total collection of classes listed in {@link Audited#auditParents()} property - * by any superclass starting with class specified as the first argument. - */ - @SuppressWarnings("unchecked") - private void doGetDeclaredAuditedSuperclasses(XClass clazz, Set declaredAuditedSuperclasses) { - Audited allClassAudited = clazz.getAnnotation(Audited.class); - if (allClassAudited != null && allClassAudited.auditParents().length > 0) { - for (Class c : allClassAudited.auditParents()) { - XClass parentClass = reflectionManager.toXClass(c); - checkSuperclass(clazz, parentClass); - declaredAuditedSuperclasses.add(parentClass); - } - } - XClass superclass = clazz.getSuperclass(); - if (!clazz.isInterface() && !Object.class.getName().equals(superclass.getName())) { - doGetDeclaredAuditedSuperclasses(superclass, declaredAuditedSuperclasses); - } - } - /** * Checks whether one class is assignable from another. If not {@link MappingException} is thrown. * @param child Subclass. @@ -229,19 +238,26 @@ public class AuditedPropertiesReader { /** * @param clazz Class which properties are currently being added. - * @param declaredAuditedSuperclasses Collection of superclasses that have been explicitly declared to be audited. * @return {@link Audited} annotation of specified class. If processed type hasn't been explicitly marked, method - * checks whether given class exists in collection passed as the second argument. In case of success, - * {@link Audited} configuration of currently mapped entity is returned, otherwise {@code null}. + * checks whether given class exists in {@code overriddenAuditedClasses} collection. In case of success, + * {@link Audited} configuration of currently mapped entity is returned (or the default if {@link Audited} + * applied on property level), otherwise {@code null}. If processed type exists in + * {@code overriddenNotAuditedClasses} collection, the result is also {@code null}. */ - private Audited computeAuditConfiguration(XClass clazz, Set declaredAuditedSuperclasses) { + private Audited computeAuditConfiguration(XClass clazz) { Audited allClassAudited = clazz.getAnnotation(Audited.class); // If processed class is not explicitly marked with @Audited annotation, check whether auditing is - // forced by any of its child entities configuration (@Audited.auditParents). - if (allClassAudited == null && declaredAuditedSuperclasses.contains(clazz)) { + // forced by any of its child entities configuration (@AuditedOverride.forClass). + if (allClassAudited == null && overriddenAuditedClasses.contains(clazz)) { // Declared audited parent copies @Audited.modStore and @Audited.targetAuditMode configuration from // currently mapped entity. allClassAudited = persistentPropertiesSource.getXClass().getAnnotation(Audited.class); + if (allClassAudited == null) { + // If parent class declares @Audited on the field/property level. + allClassAudited = DEFAULT_AUDITED; + } + } else if (allClassAudited != null && overriddenNotAuditedClasses.contains(clazz)) { + return null; } return allClassAudited; } @@ -249,11 +265,9 @@ public class AuditedPropertiesReader { /** * Recursively adds all audited properties of entity class and its superclasses. * @param clazz Currently processed class. - * @param declaredAuditedSuperclasses Collection of classes that are declared to be audited - * (see {@link Audited#auditParents()}). */ - private void addPropertiesFromClass(XClass clazz, Set declaredAuditedSuperclasses) { - Audited allClassAudited = computeAuditConfiguration(clazz, declaredAuditedSuperclasses); + private void addPropertiesFromClass(XClass clazz) { + Audited allClassAudited = computeAuditConfiguration(clazz); //look in the class addFromProperties(clazz.getDeclaredProperties("field"), "field", fieldAccessedPersistentProperties, allClassAudited); @@ -262,7 +276,7 @@ public class AuditedPropertiesReader { if(allClassAudited != null || !auditedPropertiesHolder.isEmpty()) { XClass superclazz = clazz.getSuperclass(); if (!clazz.isInterface() && !"java.lang.Object".equals(superclazz.getName())) { - addPropertiesFromClass(superclazz, declaredAuditedSuperclasses); + addPropertiesFromClass(superclazz); } } } @@ -400,34 +414,20 @@ public class AuditedPropertiesReader { PropertyAuditingData propertyData, Audited allClassAudited) { // Checking if this property is explicitly audited or if all properties are. Audited aud = (property.isAnnotationPresent(Audited.class)) ? (property.getAnnotation(Audited.class)) : allClassAudited; - //Audited aud = property.getAnnotation(Audited.class); + if (aud == null && overriddenAuditedProperties.contains(property) && !overriddenNotAuditedProperties.contains(property)) { + // Assigning @Audited defaults. If anyone needs to customize those values in the future, + // appropriate fields shall be added to @AuditOverride annotation. + aud = DEFAULT_AUDITED; + } if (aud != null) { propertyData.setStore(aud.modStore()); propertyData.setRelationTargetAuditMode(aud.targetAuditMode()); return true; - } else if (overriddenAuditedProperties.contains(property)) { - // Filling property data with @Audited defaults. If anyone needs to customize those values in the future, - // appropriate fields shall be added to @AuditOverride annotation. - fillAuditedDefaults(propertyData); - return true; } else { return false; } } - /** - * Fills given property data with default values of @Audited.modStore and @Audited.targetAuditMode attributes. - * @param propertyData Property data. - */ - private void fillAuditedDefaults(PropertyAuditingData propertyData) { - try { - propertyData.setStore((ModificationStore) Audited.class.getMethod("modStore").getDefaultValue()); - propertyData.setRelationTargetAuditMode((RelationTargetAuditMode) Audited.class.getMethod("targetAuditMode").getDefaultValue()); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - private void setPropertyAuditMappedBy(XProperty property, PropertyAuditingData propertyData) { AuditMappedBy auditMappedBy = property.getAnnotation(AuditMappedBy.class); if (auditMappedBy != null) { @@ -503,6 +503,13 @@ public class AuditedPropertiesReader { return true; } + private static Audited DEFAULT_AUDITED = new Audited() { + public ModificationStore modStore() { return ModificationStore.FULL; } + public RelationTargetAuditMode targetAuditMode() { return RelationTargetAuditMode.AUDITED; } + public Class[] auditParents() { return new Class[0]; } + public Class annotationType() { return this.getClass(); } + }; + private static AuditJoinTable DEFAULT_AUDIT_JOIN_TABLE = new AuditJoinTable() { public String name() { return ""; } public String schema() { return ""; } diff --git a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditClassOverrideTest.java b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditClassOverrideTest.java new file mode 100644 index 0000000000..962fe1b873 --- /dev/null +++ b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditClassOverrideTest.java @@ -0,0 +1,78 @@ +package org.hibernate.envers.test.integration.superclass.auditoverride; + +import org.hibernate.ejb.Ejb3Configuration; +import org.hibernate.envers.test.AbstractEntityTest; +import org.hibernate.envers.test.Priority; +import org.hibernate.mapping.Column; +import org.hibernate.mapping.Table; +import org.hibernate.testing.TestForIssue; +import org.junit.Assert; +import org.junit.Test; + +import javax.persistence.EntityManager; + +/** + * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) + */ +@TestForIssue(jiraKey = "HHH-4439") +public class AuditClassOverrideTest extends AbstractEntityTest { + private Integer classAuditedEntityId = null; + private Integer classNotAuditedEntityId = null; + private Table classAuditedTable = null; + private Table classNotAuditedTable = null; + + @Override + public void configure(Ejb3Configuration cfg) { + cfg.addAnnotatedClass(ClassOverrideAuditedEntity.class); + cfg.addAnnotatedClass(ClassOverrideNotAuditedEntity.class); + } + + @Test + @Priority(10) + public void initData() { + EntityManager em = getEntityManager(); + + // Revision 1 + em.getTransaction().begin(); + ClassOverrideAuditedEntity classOverrideAuditedEntity = new ClassOverrideAuditedEntity("data 1", 1, "data 2"); + em.persist(classOverrideAuditedEntity); + em.getTransaction().commit(); + classAuditedEntityId = classOverrideAuditedEntity.getId(); + + // Revision 2 + em.getTransaction().begin(); + ClassOverrideNotAuditedEntity classOverrideNotAuditedEntity = new ClassOverrideNotAuditedEntity("data 1", 1, "data 2"); + em.persist(classOverrideNotAuditedEntity); + em.getTransaction().commit(); + classNotAuditedEntityId = classOverrideNotAuditedEntity.getId(); + + classAuditedTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditoverride.ClassOverrideAuditedEntity_AUD").getTable(); + classNotAuditedTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditoverride.ClassOverrideNotAuditedEntity_AUD").getTable(); + } + + @Test + public void testAuditedProperty() { + Assert.assertNotNull(classAuditedTable.getColumn(new Column("number1"))); + Assert.assertNotNull(classAuditedTable.getColumn(new Column("str1"))); + Assert.assertNotNull(classAuditedTable.getColumn(new Column("str2"))); + Assert.assertNotNull(classNotAuditedTable.getColumn(new Column("str2"))); + } + + @Test + public void testNotAuditedProperty() { + Assert.assertNull(classNotAuditedTable.getColumn(new Column("number1"))); + Assert.assertNull(classNotAuditedTable.getColumn(new Column("str1"))); + } + + @Test + public void testHistoryOfClassOverrideAuditedEntity() { + ClassOverrideAuditedEntity ver1 = new ClassOverrideAuditedEntity("data 1", 1, classAuditedEntityId, "data 2"); + Assert.assertEquals(ver1, getAuditReader().find(ClassOverrideAuditedEntity.class, classAuditedEntityId, 1)); + } + + @Test + public void testHistoryOfClassOverrideNotAuditedEntity() { + ClassOverrideNotAuditedEntity ver1 = new ClassOverrideNotAuditedEntity(null, null, classNotAuditedEntityId, "data 2"); + Assert.assertEquals(ver1, getAuditReader().find(ClassOverrideNotAuditedEntity.class, classNotAuditedEntityId, 2)); + } +} diff --git a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditOverrideTest.java b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditPropertyOverrideTest.java similarity index 79% rename from hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditOverrideTest.java rename to hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditPropertyOverrideTest.java index 2dc08adee2..014477bf86 100644 --- a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditOverrideTest.java +++ b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditPropertyOverrideTest.java @@ -15,7 +15,7 @@ import javax.persistence.EntityManager; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @TestForIssue(jiraKey = "HHH-4439") -public class AuditOverrideTest extends AbstractEntityTest { +public class AuditPropertyOverrideTest extends AbstractEntityTest { private Integer propertyEntityId = null; private Integer transitiveEntityId = null; private Integer auditedEntityId = null; @@ -25,8 +25,8 @@ public class AuditOverrideTest extends AbstractEntityTest { @Override public void configure(Ejb3Configuration cfg) { - cfg.addAnnotatedClass(PropertyOverrideTestEntity.class); - cfg.addAnnotatedClass(TransitiveOverrideTestEntity.class); + cfg.addAnnotatedClass(PropertyOverrideEntity.class); + cfg.addAnnotatedClass(TransitiveOverrideEntity.class); cfg.addAnnotatedClass(AuditedSpecialEntity.class); } @@ -37,14 +37,14 @@ public class AuditOverrideTest extends AbstractEntityTest { // Revision 1 em.getTransaction().begin(); - PropertyOverrideTestEntity propertyEntity = new PropertyOverrideTestEntity("data 1", 1, "data 2"); + PropertyOverrideEntity propertyEntity = new PropertyOverrideEntity("data 1", 1, "data 2"); em.persist(propertyEntity); em.getTransaction().commit(); propertyEntityId = propertyEntity.getId(); // Revision 2 em.getTransaction().begin(); - TransitiveOverrideTestEntity transitiveEntity = new TransitiveOverrideTestEntity("data 1", 1, "data 2", 2, "data 3"); + TransitiveOverrideEntity transitiveEntity = new TransitiveOverrideEntity("data 1", 1, "data 2", 2, "data 3"); em.persist(transitiveEntity); em.getTransaction().commit(); transitiveEntityId = transitiveEntity.getId(); @@ -56,8 +56,8 @@ public class AuditOverrideTest extends AbstractEntityTest { em.getTransaction().commit(); auditedEntityId = auditedEntity.getId(); - propertyTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditoverride.PropertyOverrideTestEntity_AUD").getTable(); - transitiveTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditoverride.TransitiveOverrideTestEntity_AUD").getTable(); + propertyTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditoverride.PropertyOverrideEntity_AUD").getTable(); + transitiveTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditoverride.TransitiveOverrideEntity_AUD").getTable(); auditedTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.superclass.auditoverride.AuditedSpecialEntity_AUD").getTable(); } @@ -81,14 +81,14 @@ public class AuditOverrideTest extends AbstractEntityTest { @Test public void testHistoryOfPropertyOverrideEntity() { - PropertyOverrideTestEntity ver1 = new PropertyOverrideTestEntity(null, 1, propertyEntityId, "data 2"); - Assert.assertEquals(ver1, getAuditReader().find(PropertyOverrideTestEntity.class, propertyEntityId, 1)); + PropertyOverrideEntity ver1 = new PropertyOverrideEntity(null, 1, propertyEntityId, "data 2"); + Assert.assertEquals(ver1, getAuditReader().find(PropertyOverrideEntity.class, propertyEntityId, 1)); } @Test public void testHistoryOfTransitiveOverrideEntity() { - TransitiveOverrideTestEntity ver1 = new TransitiveOverrideTestEntity("data 1", 1, transitiveEntityId, "data 2", 2, "data 3"); - Assert.assertEquals(ver1, getAuditReader().find(TransitiveOverrideTestEntity.class, transitiveEntityId, 2)); + TransitiveOverrideEntity ver1 = new TransitiveOverrideEntity("data 1", 1, transitiveEntityId, "data 2", 2, "data 3"); + Assert.assertEquals(ver1, getAuditReader().find(TransitiveOverrideEntity.class, transitiveEntityId, 2)); } @Test diff --git a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditedBaseEntity.java b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditedBaseEntity.java new file mode 100644 index 0000000000..0ae8ff9fe5 --- /dev/null +++ b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditedBaseEntity.java @@ -0,0 +1,86 @@ +package org.hibernate.envers.test.integration.superclass.auditoverride; + +import org.hibernate.envers.Audited; + +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; +import java.io.Serializable; + +/** + * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) + */ +@Audited +@MappedSuperclass +public class AuditedBaseEntity implements Serializable { + @Id + @GeneratedValue + private Integer id; + + private String str1; + + private Integer number1; + + public AuditedBaseEntity() { + } + + public AuditedBaseEntity(String str1, Integer number1, Integer id) { + this.id = id; + this.str1 = str1; + this.number1 = number1; + } + + public AuditedBaseEntity(String str1, Integer number1) { + this.str1 = str1; + this.number1 = number1; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getStr1() { + return str1; + } + + public void setStr1(String str1) { + this.str1 = str1; + } + + public Integer getNumber1() { + return number1; + } + + public void setNumber1(Integer number1) { + this.number1 = number1; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof AuditedBaseEntity)) return false; + + AuditedBaseEntity that = (AuditedBaseEntity) o; + + if (id != null ? !id.equals(that.id) : that.id != null) return false; + if (number1 != null ? !number1.equals(that.number1) : that.number1 != null) return false; + if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false; + + return true; + } + + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (str1 != null ? str1.hashCode() : 0); + result = 31 * result + (number1 != null ? number1.hashCode() : 0); + return result; + } + + public String toString() { + return "AuditedBaseEntity(id = " + id + ", str1 = " + str1 + ", number1 = " + number1 + ")"; + } +} diff --git a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditedSpecialEntity.java b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditedSpecialEntity.java index 13b4dae19b..aac603fce0 100644 --- a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditedSpecialEntity.java +++ b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/AuditedSpecialEntity.java @@ -10,8 +10,8 @@ import javax.persistence.Entity; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @Entity -@AuditOverrides({@AuditOverride(relatedClass = NotAnnotatedBaseEntity.class, name = "str1", isAudited = true)}) -public class AuditedSpecialEntity extends NotAnnotatedBaseEntity { +@AuditOverrides({@AuditOverride(forClass = NotAuditedBaseEntity.class, name = "str1", isAudited = true)}) +public class AuditedSpecialEntity extends NotAuditedBaseEntity { @Audited private String str2; diff --git a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/ClassOverrideAuditedEntity.java b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/ClassOverrideAuditedEntity.java new file mode 100644 index 0000000000..8c0702e053 --- /dev/null +++ b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/ClassOverrideAuditedEntity.java @@ -0,0 +1,63 @@ +package org.hibernate.envers.test.integration.superclass.auditoverride; + +import org.hibernate.envers.AuditOverride; +import org.hibernate.envers.AuditOverrides; +import org.hibernate.envers.Audited; + +import javax.persistence.Entity; + +/** + * @author Lukasz Antoniak (lukasz.antoniak at gmail dot com) + */ +@Entity +@AuditOverrides({@AuditOverride(forClass = NotAuditedBaseEntity.class, isAudited = true)}) +public class ClassOverrideAuditedEntity extends NotAuditedBaseEntity { + @Audited + private String str2; + + public ClassOverrideAuditedEntity() { + } + + public ClassOverrideAuditedEntity(String str1, Integer number, String str2) { + super(str1, number); + this.str2 = str2; + } + + public ClassOverrideAuditedEntity(String str1, Integer number, Integer id, String str2) { + super(str1, number, id); + this.str2 = str2; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ClassOverrideAuditedEntity)) return false; + if (!super.equals(o)) return false; + + ClassOverrideAuditedEntity that = (ClassOverrideAuditedEntity) o; + + if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (str2 != null ? str2.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "ClassOverrideAuditedEntity(" + super.toString() + ", str2 = " + str2 + ")"; + } + + public String getStr2() { + return str2; + } + + public void setStr2(String str2) { + this.str2 = str2; + } +} diff --git a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/ClassOverrideNotAuditedEntity.java b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/ClassOverrideNotAuditedEntity.java new file mode 100644 index 0000000000..0c4bdd2f67 --- /dev/null +++ b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/ClassOverrideNotAuditedEntity.java @@ -0,0 +1,63 @@ +package org.hibernate.envers.test.integration.superclass.auditoverride; + +import org.hibernate.envers.AuditOverride; +import org.hibernate.envers.AuditOverrides; +import org.hibernate.envers.Audited; + +import javax.persistence.Entity; + +/** + * @author Lukasz Antoniak (lukasz.antoniak at gmail dot com) + */ +@Entity +@AuditOverrides({@AuditOverride(forClass = AuditedBaseEntity.class, isAudited = false)}) +public class ClassOverrideNotAuditedEntity extends AuditedBaseEntity { + @Audited + private String str2; + + public ClassOverrideNotAuditedEntity() { + } + + public ClassOverrideNotAuditedEntity(String str1, Integer number, String str2) { + super(str1, number); + this.str2 = str2; + } + + public ClassOverrideNotAuditedEntity(String str1, Integer number, Integer id, String str2) { + super(str1, number, id); + this.str2 = str2; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ClassOverrideNotAuditedEntity)) return false; + if (!super.equals(o)) return false; + + ClassOverrideNotAuditedEntity that = (ClassOverrideNotAuditedEntity) o; + + if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (str2 != null ? str2.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "ClassOverrideNotAuditedEntity(" + super.toString() + ", str2 = " + str2 + ")"; + } + + public String getStr2() { + return str2; + } + + public void setStr2(String str2) { + this.str2 = str2; + } +} diff --git a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/ExtendedBaseEntity.java b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/ExtendedBaseEntity.java index 92d8eb5f12..d4137d8a70 100644 --- a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/ExtendedBaseEntity.java +++ b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/ExtendedBaseEntity.java @@ -11,8 +11,8 @@ import javax.persistence.MappedSuperclass; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @MappedSuperclass -@AuditOverrides({@AuditOverride(relatedClass = BaseEntity.class, name = "str1", isAudited = false), - @AuditOverride(relatedClass = BaseEntity.class, name = "number1", isAudited = true)}) +@AuditOverrides({@AuditOverride(forClass = BaseEntity.class, name = "str1", isAudited = false), + @AuditOverride(forClass = BaseEntity.class, name = "number1", isAudited = true)}) public class ExtendedBaseEntity extends BaseEntity { @Audited private String str2; diff --git a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/NotAnnotatedBaseEntity.java b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/NotAuditedBaseEntity.java similarity index 77% rename from hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/NotAnnotatedBaseEntity.java rename to hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/NotAuditedBaseEntity.java index e957fea741..f83655bdff 100644 --- a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/NotAnnotatedBaseEntity.java +++ b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/NotAuditedBaseEntity.java @@ -9,7 +9,7 @@ import java.io.Serializable; * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @MappedSuperclass -public class NotAnnotatedBaseEntity implements Serializable { +public class NotAuditedBaseEntity implements Serializable { @Id @GeneratedValue private Integer id; @@ -18,16 +18,16 @@ public class NotAnnotatedBaseEntity implements Serializable { private Integer number1; - public NotAnnotatedBaseEntity() { + public NotAuditedBaseEntity() { } - public NotAnnotatedBaseEntity(String str1, Integer number1, Integer id) { + public NotAuditedBaseEntity(String str1, Integer number1, Integer id) { this.id = id; this.str1 = str1; this.number1 = number1; } - public NotAnnotatedBaseEntity(String str1, Integer number1) { + public NotAuditedBaseEntity(String str1, Integer number1) { this.str1 = str1; this.number1 = number1; } @@ -58,9 +58,9 @@ public class NotAnnotatedBaseEntity implements Serializable { public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof NotAnnotatedBaseEntity)) return false; + if (!(o instanceof NotAuditedBaseEntity)) return false; - NotAnnotatedBaseEntity that = (NotAnnotatedBaseEntity) o; + NotAuditedBaseEntity that = (NotAuditedBaseEntity) o; if (id != null ? !id.equals(that.id) : that.id != null) return false; if (number1 != null ? !number1.equals(that.number1) : that.number1 != null) return false; @@ -78,6 +78,6 @@ public class NotAnnotatedBaseEntity implements Serializable { } public String toString() { - return "NotAnnotatedBaseEntity(id = " + id + ", str1 = " + str1 + ", number1 = " + number1 + ")"; + return "NotAuditedBaseEntity(id = " + id + ", str1 = " + str1 + ", number1 = " + number1 + ")"; } } \ No newline at end of file diff --git a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/PropertyOverrideTestEntity.java b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/PropertyOverrideEntity.java similarity index 60% rename from hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/PropertyOverrideTestEntity.java rename to hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/PropertyOverrideEntity.java index 6e170f90f5..783d1e4ad8 100644 --- a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/PropertyOverrideTestEntity.java +++ b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/PropertyOverrideEntity.java @@ -11,20 +11,20 @@ import javax.persistence.Entity; */ @Entity @Audited -@AuditOverrides({@AuditOverride(relatedClass = BaseEntity.class, name = "str1", isAudited = false), - @AuditOverride(relatedClass = BaseEntity.class, name = "number1", isAudited = true)}) -public class PropertyOverrideTestEntity extends BaseEntity { +@AuditOverrides({@AuditOverride(forClass = BaseEntity.class, name = "str1", isAudited = false), + @AuditOverride(forClass = BaseEntity.class, name = "number1", isAudited = true)}) +public class PropertyOverrideEntity extends BaseEntity { private String str2; - public PropertyOverrideTestEntity() { + public PropertyOverrideEntity() { } - public PropertyOverrideTestEntity(String str1, Integer number1, String str2) { + public PropertyOverrideEntity(String str1, Integer number1, String str2) { super(str1, number1); this.str2 = str2; } - public PropertyOverrideTestEntity(String str1, Integer number1, Integer id, String str2) { + public PropertyOverrideEntity(String str1, Integer number1, Integer id, String str2) { super(str1, number1, id); this.str2 = str2; } @@ -32,10 +32,10 @@ public class PropertyOverrideTestEntity extends BaseEntity { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof PropertyOverrideTestEntity)) return false; + if (!(o instanceof PropertyOverrideEntity)) return false; if (!super.equals(o)) return false; - PropertyOverrideTestEntity that = (PropertyOverrideTestEntity) o; + PropertyOverrideEntity that = (PropertyOverrideEntity) o; if (str2 != null ? !str2.equals(that.str2) : that.str2 != null) return false; @@ -51,7 +51,7 @@ public class PropertyOverrideTestEntity extends BaseEntity { @Override public String toString() { - return "PropertyOverrideTestEntity(" + super.toString() + ", str2 = " + str2 + ")"; + return "PropertyOverrideEntity(" + super.toString() + ", str2 = " + str2 + ")"; } public String getStr2() { diff --git a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/TransitiveOverrideTestEntity.java b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/TransitiveOverrideEntity.java similarity index 58% rename from hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/TransitiveOverrideTestEntity.java rename to hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/TransitiveOverrideEntity.java index f068815826..72dc9069df 100644 --- a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/TransitiveOverrideTestEntity.java +++ b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/superclass/auditoverride/TransitiveOverrideEntity.java @@ -11,20 +11,20 @@ import javax.persistence.Entity; */ @Entity @Audited -@AuditOverrides({@AuditOverride(relatedClass = BaseEntity.class, name = "str1", isAudited = true), - @AuditOverride(relatedClass = ExtendedBaseEntity.class, name = "number2", isAudited = true)}) -public class TransitiveOverrideTestEntity extends ExtendedBaseEntity { +@AuditOverrides({@AuditOverride(forClass = BaseEntity.class, name = "str1", isAudited = true), + @AuditOverride(forClass = ExtendedBaseEntity.class, name = "number2", isAudited = true)}) +public class TransitiveOverrideEntity extends ExtendedBaseEntity { private String str3; - public TransitiveOverrideTestEntity() { + public TransitiveOverrideEntity() { } - public TransitiveOverrideTestEntity(String str1, Integer number1, Integer id, String str2, Integer number2, String str3) { + public TransitiveOverrideEntity(String str1, Integer number1, Integer id, String str2, Integer number2, String str3) { super(str1, number1, id, str2, number2); this.str3 = str3; } - public TransitiveOverrideTestEntity(String str1, Integer number1, String str2, Integer number2, String str3) { + public TransitiveOverrideEntity(String str1, Integer number1, String str2, Integer number2, String str3) { super(str1, number1, str2, number2); this.str3 = str3; } @@ -32,10 +32,10 @@ public class TransitiveOverrideTestEntity extends ExtendedBaseEntity { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof TransitiveOverrideTestEntity)) return false; + if (!(o instanceof TransitiveOverrideEntity)) return false; if (!super.equals(o)) return false; - TransitiveOverrideTestEntity that = (TransitiveOverrideTestEntity) o; + TransitiveOverrideEntity that = (TransitiveOverrideEntity) o; if (str3 != null ? !str3.equals(that.str3) : that.str3 != null) return false; @@ -51,7 +51,7 @@ public class TransitiveOverrideTestEntity extends ExtendedBaseEntity { @Override public String toString() { - return "TransitiveOverrideTestEntity(" + super.toString() + ", str3 = " + str3 + ")"; + return "TransitiveOverrideEntity(" + super.toString() + ", str3 = " + str3 + ")"; } public String getStr3() {