From 6f3c564b9ae240717e705f93db6f311292e4f3a8 Mon Sep 17 00:00:00 2001 From: Michal Skowronek Date: Wed, 25 May 2011 02:57:55 +0200 Subject: [PATCH] Extended test cases and provided a fix for the issue The idea for the fix is to simply stop using properties tag for relations in favor of plain (possibly multiple) propeties --- .../ToOneRelationMetadataGenerator.java | 10 +++- .../mapper/relation/ToOneIdMapper.java | 22 +++++--- .../criteria/NotNullAuditExpression.java | 2 +- .../query/criteria/NullAuditExpression.java | 2 +- .../criteria/RelatedAuditExpression.java | 2 +- .../query/criteria/SimpleAuditExpression.java | 2 +- ...tractInheritanceStrategiesSessionTest.java | 55 ++++++++++-------- .../JoinedSubclassInheritanceSessionTest.java | 2 +- .../MixedInheritanceStrategiesEntityTest.java | 56 ++++++++++--------- ...MixedInheritanceStrategiesSessionTest.java | 5 +- .../mixed/entities/AbstractActivity.java | 13 +++-- .../mixed/entities/AbstractCheckActivity.java | 7 ++- .../inheritance/mixed/entities/Activity.java | 6 +- .../mixed/entities/ActivityId.java | 53 ++++++++++++++++++ .../test/integration/naming/JoinNaming.java | 21 +++---- .../naming/ids/JoinEmbIdNaming.java | 30 +++++----- .../naming/ids/JoinMulIdNaming.java | 31 +++++----- ...hbm.xml => mappingsJoinedSubclass.hbm.xml} | 22 ++++++-- ...sFailing.hbm.xml => mappingsMixed.hbm.xml} | 13 ++++- 19 files changed, 223 insertions(+), 131 deletions(-) create mode 100644 hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/ActivityId.java rename hibernate-envers/src/test/resources/mappings/mixedInheritanceStrategies/{mappingsPassing.hbm.xml => mappingsJoinedSubclass.hbm.xml} (66%) rename hibernate-envers/src/test/resources/mappings/mixedInheritanceStrategies/{mappingsFailing.hbm.xml => mappingsMixed.hbm.xml} (79%) diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java index f6ab5ee140..33c3857c18 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java @@ -86,9 +86,15 @@ public final class ToOneRelationMetadataGenerator { MetadataTools.prefixNamesInPropertyElement(properties, lastPropertyPrefix, MetadataTools.getColumnNameIterator(value.getColumnIterator()), false, insertable); - parent.add(properties); - // Adding mapper for the id + // Extracting related id properties from properties tag + for (Object o : properties.content()) { + Element element = (Element) o; + element.setParent(null); + parent.add(element); + } + + // Adding mapper for the id PropertyData propertyData = propertyAuditingData.getPropertyData(); mapper.addComposite(propertyData, new ToOneIdMapper(relMapper, propertyData, referencedEntityName, nonInsertableFake)); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java index 00204f25a2..8d870a1a15 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java @@ -22,10 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.envers.entities.mapper.relation; -import java.io.Serializable; -import java.util.HashMap; -import java.util.List; -import java.util.Map; + import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.configuration.AuditConfiguration; @@ -40,6 +37,11 @@ import org.hibernate.envers.tools.Tools; import org.hibernate.envers.tools.reflection.ReflectionTools; import org.hibernate.property.Setter; +import java.io.Serializable; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * @author Adam Warski (adam at warski dot org) * @author Hern�n Chanfreau @@ -59,13 +61,16 @@ public class ToOneIdMapper implements PropertyMapper { public boolean mapToMapFromEntity(SessionImplementor session, Map data, Object newObj, Object oldObj) { HashMap newData = new HashMap(); - data.put(propertyData.getName(), newData); // If this property is originally non-insertable, but made insertable because it is in a many-to-one "fake" // bi-directional relation, we always store the "old", unchaged data, to prevent storing changes made // to this field. It is the responsibility of the collection to properly update it if it really changed. delegate.mapToMapFromEntity(newData, nonInsertableFake ? oldObj : newObj); + for (Map.Entry entry : newData.entrySet()) { + data.put(entry.getKey(), entry.getValue()); + } + //noinspection SimplifiableConditionalExpression return nonInsertableFake ? false : !Tools.entitiesEqual(session, referencedEntityName, newObj, oldObj); } @@ -76,7 +81,8 @@ public class ToOneIdMapper implements PropertyMapper { return; } - Object entityId = delegate.mapToIdFromMap((Map) data.get(propertyData.getName())); + Object entityId; + entityId = delegate.mapToIdFromMap(data); Object value; if (entityId == null) { value = null; @@ -86,10 +92,10 @@ public class ToOneIdMapper implements PropertyMapper { } else { EntityConfiguration entCfg = verCfg.getEntCfg().get(referencedEntityName); if(entCfg == null) { - // a relation marked as RelationTargetAuditMode.NOT_AUDITED + // a relation marked as RelationTargetAuditMode.NOT_AUDITED entCfg = verCfg.getEntCfg().getNotVersionEntityConfiguration(referencedEntityName); } - + Class entityClass = ReflectionTools.loadClass(entCfg.getEntityClassName()); value = versionsReader.getSessionImplementor().getFactory().getEntityPersister(referencedEntityName). diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/NotNullAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/NotNullAuditExpression.java index 476277de8a..2186143b04 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/NotNullAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/NotNullAuditExpression.java @@ -45,7 +45,7 @@ public class NotNullAuditExpression implements AuditCriterion { if (relatedEntity == null) { parameters.addNotNullRestriction(propertyName, true); } else { - relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, null, propertyName, false); + relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, null, null, false); } } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/NullAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/NullAuditExpression.java index 4565256c43..09c001cada 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/NullAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/NullAuditExpression.java @@ -45,7 +45,7 @@ public class NullAuditExpression implements AuditCriterion { if (relatedEntity == null) { parameters.addNullRestriction(propertyName, true); } else { - relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, null, propertyName, true); + relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, null, null, true); } } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/RelatedAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/RelatedAuditExpression.java index c72d409928..4d6ba626b9 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/RelatedAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/RelatedAuditExpression.java @@ -52,7 +52,7 @@ public class RelatedAuditExpression implements AuditCriterion { throw new AuditException("This criterion can only be used on a property that is " + "a relation to another property."); } else { - relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, id, propertyName, equals); + relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, id, null, equals); } } } \ No newline at end of file diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/SimpleAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/SimpleAuditExpression.java index 98d41b4017..4ecf44f0cf 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/SimpleAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/SimpleAuditExpression.java @@ -58,7 +58,7 @@ public class SimpleAuditExpression implements AuditCriterion { Object id = relatedEntity.getIdMapper().mapToIdFromEntity(value); - relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, id, propertyName, "=".equals(op)); + relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, id, null, "=".equals(op)); } } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/AbstractInheritanceStrategiesSessionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/AbstractInheritanceStrategiesSessionTest.java index 0208097d19..b4777e7262 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/AbstractInheritanceStrategiesSessionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/AbstractInheritanceStrategiesSessionTest.java @@ -3,6 +3,7 @@ package org.hibernate.envers.test.integration.inheritance.mixed; import org.hibernate.envers.test.AbstractSessionTest; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.inheritance.mixed.entities.Activity; +import org.hibernate.envers.test.integration.inheritance.mixed.entities.ActivityId; import org.hibernate.envers.test.integration.inheritance.mixed.entities.CheckInActivity; import org.hibernate.envers.test.integration.inheritance.mixed.entities.NormalActivity; import org.junit.Test; @@ -15,11 +16,17 @@ import static org.junit.Assert.assertEquals; * @author Michal Skowronek (mskowr at o2 pl) */ public abstract class AbstractInheritanceStrategiesSessionTest extends AbstractSessionTest { - @Test + + private ActivityId id1; + private ActivityId id2; + private ActivityId id3; + + @Test @Priority(10) public void initData() { NormalActivity normalActivity = new NormalActivity(); - normalActivity.setId(1); + id1 = new ActivityId(1, 2); + normalActivity.setId(id1); normalActivity.setSequenceNumber(1); // Revision 1 @@ -31,9 +38,10 @@ public abstract class AbstractInheritanceStrategiesSessionTest extends AbstractS // Revision 2 getSession().getTransaction().begin(); - normalActivity = (NormalActivity) getSession().get(NormalActivity.class, 1); + normalActivity = (NormalActivity) getSession().get(NormalActivity.class, id1); CheckInActivity checkInActivity = new CheckInActivity(); - checkInActivity.setId(2); + id2 = new ActivityId(2, 3); + checkInActivity.setId(id2); checkInActivity.setSequenceNumber(0); checkInActivity.setDurationInMinutes(30); checkInActivity.setRelatedActivity(normalActivity); @@ -44,7 +52,8 @@ public abstract class AbstractInheritanceStrategiesSessionTest extends AbstractS // Revision 3 normalActivity = new NormalActivity(); - normalActivity.setId(3); + id3 = new ActivityId(3, 4); + normalActivity.setId(id3); normalActivity.setSequenceNumber(2); getSession().getTransaction().begin(); @@ -56,8 +65,8 @@ public abstract class AbstractInheritanceStrategiesSessionTest extends AbstractS // Revision 4 getSession().getTransaction().begin(); - normalActivity = (NormalActivity) getSession().get(NormalActivity.class, 3); - checkInActivity = (CheckInActivity) getSession().get(CheckInActivity.class, 2); + normalActivity = (NormalActivity) getSession().get(NormalActivity.class, id3); + checkInActivity = (CheckInActivity) getSession().get(CheckInActivity.class, id2); checkInActivity.setRelatedActivity(normalActivity); getSession().merge(checkInActivity); @@ -69,18 +78,18 @@ public abstract class AbstractInheritanceStrategiesSessionTest extends AbstractS @Test public void testRevisionsCounts() { - assertEquals(Arrays.asList(1), getAuditReader().getRevisions(NormalActivity.class, 1)); - assertEquals(Arrays.asList(3), getAuditReader().getRevisions(NormalActivity.class, 3)); - assertEquals(Arrays.asList(2, 4), getAuditReader().getRevisions(CheckInActivity.class, 2)); + assertEquals(Arrays.asList(1), getAuditReader().getRevisions(NormalActivity.class, id1)); + assertEquals(Arrays.asList(3), getAuditReader().getRevisions(NormalActivity.class, id3)); + assertEquals(Arrays.asList(2, 4), getAuditReader().getRevisions(CheckInActivity.class, id2)); } @Test public void testCurrentStateOfCheckInActivity() { - final CheckInActivity checkInActivity = (CheckInActivity) getSession().get(CheckInActivity.class, 2); - final NormalActivity normalActivity = (NormalActivity) getSession().get(NormalActivity.class, 3); + final CheckInActivity checkInActivity = (CheckInActivity) getSession().get(CheckInActivity.class, id2); + final NormalActivity normalActivity = (NormalActivity) getSession().get(NormalActivity.class, id3); - assertEquals(2, checkInActivity.getId().intValue()); + assertEquals(id2, checkInActivity.getId()); assertEquals(0, checkInActivity.getSequenceNumber().intValue()); assertEquals(30, checkInActivity.getDurationInMinutes().intValue()); final Activity relatedActivity = checkInActivity.getRelatedActivity(); @@ -90,20 +99,20 @@ public abstract class AbstractInheritanceStrategiesSessionTest extends AbstractS @Test public void testCheckCurrentStateOfNormalActivities() throws Exception { - final NormalActivity normalActivity1 = (NormalActivity) getSession().get(NormalActivity.class, 1); - final NormalActivity normalActivity2 = (NormalActivity) getSession().get(NormalActivity.class, 3); + final NormalActivity normalActivity1 = (NormalActivity) getSession().get(NormalActivity.class, id1); + final NormalActivity normalActivity2 = (NormalActivity) getSession().get(NormalActivity.class, id3); - assertEquals(1, normalActivity1.getId().intValue()); + assertEquals(id1, normalActivity1.getId()); assertEquals(1, normalActivity1.getSequenceNumber().intValue()); - assertEquals(3, normalActivity2.getId().intValue()); + assertEquals(id3, normalActivity2.getId()); assertEquals(2, normalActivity2.getSequenceNumber().intValue()); } public void doTestFirstRevisionOfCheckInActivity() throws Exception { - CheckInActivity checkInActivity = getAuditReader().find(CheckInActivity.class, 2, 2); - NormalActivity normalActivity = getAuditReader().find(NormalActivity.class, 1, 2); + CheckInActivity checkInActivity = getAuditReader().find(CheckInActivity.class, id2, 2); + NormalActivity normalActivity = getAuditReader().find(NormalActivity.class, id1, 2); - assertEquals(2, checkInActivity.getId().intValue()); + assertEquals(id2, checkInActivity.getId()); assertEquals(0, checkInActivity.getSequenceNumber().intValue()); assertEquals(30, checkInActivity.getDurationInMinutes().intValue()); Activity relatedActivity = checkInActivity.getRelatedActivity(); @@ -112,10 +121,10 @@ public abstract class AbstractInheritanceStrategiesSessionTest extends AbstractS } public void doTestSecondRevisionOfCheckInActivity() throws Exception { - CheckInActivity checkInActivity = getAuditReader().find(CheckInActivity.class, 2, 4); - NormalActivity normalActivity = getAuditReader().find(NormalActivity.class, 3, 4); + CheckInActivity checkInActivity = getAuditReader().find(CheckInActivity.class, id2, 4); + NormalActivity normalActivity = getAuditReader().find(NormalActivity.class, id3, 4); - assertEquals(2, checkInActivity.getId().intValue()); + assertEquals(id2, checkInActivity.getId()); assertEquals(0, checkInActivity.getSequenceNumber().intValue()); assertEquals(30, checkInActivity.getDurationInMinutes().intValue()); Activity relatedActivity = checkInActivity.getRelatedActivity(); diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/JoinedSubclassInheritanceSessionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/JoinedSubclassInheritanceSessionTest.java index 565f500324..495eec11d6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/JoinedSubclassInheritanceSessionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/JoinedSubclassInheritanceSessionTest.java @@ -14,7 +14,7 @@ public class JoinedSubclassInheritanceSessionTest extends AbstractInheritanceStr protected void initMappings() throws MappingException, URISyntaxException { URL url = Thread.currentThread().getContextClassLoader().getResource( - "mappings/mixedInheritanceStrategies/mappingsPassing.hbm.xml"); + "mappings/mixedInheritanceStrategies/mappingsJoinedSubclass.hbm.xml"); config.addFile(new File(url.toURI())); } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesEntityTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesEntityTest.java index 8ddbffa989..934dd333c2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesEntityTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesEntityTest.java @@ -4,7 +4,6 @@ import org.hibernate.ejb.Ejb3Configuration; import org.hibernate.envers.test.AbstractEntityTest; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.integration.inheritance.mixed.entities.*; -import org.hibernate.testing.FailureExpected; import org.junit.Test; import java.util.Arrays; @@ -16,7 +15,11 @@ import static org.junit.Assert.assertEquals; */ public class MixedInheritanceStrategiesEntityTest extends AbstractEntityTest { - @Override + private ActivityId id2; + private ActivityId id1; + private ActivityId id3; + + @Override public void configure(Ejb3Configuration cfg) { cfg.addAnnotatedClass(AbstractActivity.class); cfg.addAnnotatedClass(AbstractCheckActivity.class); @@ -28,7 +31,8 @@ public class MixedInheritanceStrategiesEntityTest extends AbstractEntityTest { @Priority(10) public void initData() { NormalActivity normalActivity = new NormalActivity(); - normalActivity.setId(1); + id1 = new ActivityId(1, 2); + normalActivity.setId(id1); normalActivity.setSequenceNumber(1); // Revision 1 @@ -40,9 +44,10 @@ public class MixedInheritanceStrategiesEntityTest extends AbstractEntityTest { // Revision 2 getEntityManager().getTransaction().begin(); - normalActivity = getEntityManager().find(NormalActivity.class, 1); + normalActivity = getEntityManager().find(NormalActivity.class, id1); CheckInActivity checkInActivity = new CheckInActivity(); - checkInActivity.setId(2); + id2 = new ActivityId(2, 3); + checkInActivity.setId(id2); checkInActivity.setSequenceNumber(0); checkInActivity.setDurationInMinutes(30); checkInActivity.setRelatedActivity(normalActivity); @@ -53,7 +58,8 @@ public class MixedInheritanceStrategiesEntityTest extends AbstractEntityTest { // Revision 3 normalActivity = new NormalActivity(); - normalActivity.setId(3); + id3 = new ActivityId(3, 4); + normalActivity.setId(id3); normalActivity.setSequenceNumber(2); getEntityManager().getTransaction().begin(); @@ -65,8 +71,8 @@ public class MixedInheritanceStrategiesEntityTest extends AbstractEntityTest { // Revision 4 getEntityManager().getTransaction().begin(); - normalActivity = getEntityManager().find(NormalActivity.class, 3); - checkInActivity = getEntityManager().find(CheckInActivity.class, 2); + normalActivity = getEntityManager().find(NormalActivity.class, id3); + checkInActivity = getEntityManager().find(CheckInActivity.class, id2); checkInActivity.setRelatedActivity(normalActivity); getEntityManager().merge(checkInActivity); @@ -76,18 +82,18 @@ public class MixedInheritanceStrategiesEntityTest extends AbstractEntityTest { @Test public void testRevisionsCounts() { - assertEquals(Arrays.asList(1), getAuditReader().getRevisions(NormalActivity.class, 1)); - assertEquals(Arrays.asList(3), getAuditReader().getRevisions(NormalActivity.class, 3)); - assertEquals(Arrays.asList(2, 4), getAuditReader().getRevisions(CheckInActivity.class, 2)); + assertEquals(Arrays.asList(1), getAuditReader().getRevisions(NormalActivity.class, id1)); + assertEquals(Arrays.asList(3), getAuditReader().getRevisions(NormalActivity.class, id3)); + assertEquals(Arrays.asList(2, 4), getAuditReader().getRevisions(CheckInActivity.class, id2)); } @Test public void testCurrentStateOfCheckInActivity() { - final CheckInActivity checkInActivity = getEntityManager().find(CheckInActivity.class, 2); - final NormalActivity normalActivity = getEntityManager().find(NormalActivity.class, 3); + final CheckInActivity checkInActivity = getEntityManager().find(CheckInActivity.class, id2); + final NormalActivity normalActivity = getEntityManager().find(NormalActivity.class, id3); - assertEquals(2, checkInActivity.getId().intValue()); + assertEquals(id2, checkInActivity.getId()); assertEquals(0, checkInActivity.getSequenceNumber().intValue()); assertEquals(30, checkInActivity.getDurationInMinutes().intValue()); final Activity relatedActivity = checkInActivity.getRelatedActivity(); @@ -97,22 +103,21 @@ public class MixedInheritanceStrategiesEntityTest extends AbstractEntityTest { @Test public void testCheckCurrentStateOfNormalActivities() throws Exception { - final NormalActivity normalActivity1 = getEntityManager().find(NormalActivity.class, 1); - final NormalActivity normalActivity2 = getEntityManager().find(NormalActivity.class, 3); + final NormalActivity normalActivity1 = getEntityManager().find(NormalActivity.class, id1); + final NormalActivity normalActivity2 = getEntityManager().find(NormalActivity.class, id3); - assertEquals(1, normalActivity1.getId().intValue()); + assertEquals(id1, normalActivity1.getId()); assertEquals(1, normalActivity1.getSequenceNumber().intValue()); - assertEquals(3, normalActivity2.getId().intValue()); + assertEquals(id3, normalActivity2.getId()); assertEquals(2, normalActivity2.getSequenceNumber().intValue()); } @Test - @FailureExpected(message = "Problem with mixed inheritance strategies", jiraKey = "HHH-6177") public void doTestFirstRevisionOfCheckInActivity() throws Exception { - CheckInActivity checkInActivity = getAuditReader().find(CheckInActivity.class, 2, 2); - NormalActivity normalActivity = getAuditReader().find(NormalActivity.class, 1, 2); + CheckInActivity checkInActivity = getAuditReader().find(CheckInActivity.class, id2, 2); + NormalActivity normalActivity = getAuditReader().find(NormalActivity.class, id1, 2); - assertEquals(2, checkInActivity.getId().intValue()); + assertEquals(id2, checkInActivity.getId()); assertEquals(0, checkInActivity.getSequenceNumber().intValue()); assertEquals(30, checkInActivity.getDurationInMinutes().intValue()); Activity relatedActivity = checkInActivity.getRelatedActivity(); @@ -121,12 +126,11 @@ public class MixedInheritanceStrategiesEntityTest extends AbstractEntityTest { } @Test - @FailureExpected(message = "Problem with mixed inheritance strategies", jiraKey = "HHH-6177") public void doTestSecondRevisionOfCheckInActivity() throws Exception { - CheckInActivity checkInActivity = getAuditReader().find(CheckInActivity.class, 2, 4); - NormalActivity normalActivity = getAuditReader().find(NormalActivity.class, 3, 4); + CheckInActivity checkInActivity = getAuditReader().find(CheckInActivity.class, id2, 4); + NormalActivity normalActivity = getAuditReader().find(NormalActivity.class, id3, 4); - assertEquals(2, checkInActivity.getId().intValue()); + assertEquals(id2, checkInActivity.getId()); assertEquals(0, checkInActivity.getSequenceNumber().intValue()); assertEquals(30, checkInActivity.getDurationInMinutes().intValue()); Activity relatedActivity = checkInActivity.getRelatedActivity(); diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesSessionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesSessionTest.java index d1d75a6fee..4b9d874054 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesSessionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesSessionTest.java @@ -1,7 +1,6 @@ package org.hibernate.envers.test.integration.inheritance.mixed; import org.hibernate.MappingException; -import org.hibernate.testing.FailureExpected; import org.junit.Test; import java.io.File; @@ -15,18 +14,16 @@ public class MixedInheritanceStrategiesSessionTest extends AbstractInheritanceSt protected void initMappings() throws MappingException, URISyntaxException { URL url = Thread.currentThread().getContextClassLoader().getResource( - "mappings/mixedInheritanceStrategies/mappingsFailing.hbm.xml"); + "mappings/mixedInheritanceStrategies/mappingsMixed.hbm.xml"); config.addFile(new File(url.toURI())); } @Test - @FailureExpected(message = "Problem with mixed inheritance strategies", jiraKey = "HHH-6177") public void testFirstRevisionOfCheckInActivity() throws Exception { doTestFirstRevisionOfCheckInActivity(); } @Test - @FailureExpected(message = "Problem with mixed inheritance strategies", jiraKey = "HHH-6177") public void testSecondRevisionOfCheckInActivity() throws Exception { doTestSecondRevisionOfCheckInActivity(); } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/AbstractActivity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/AbstractActivity.java index c79380a1f6..256a07c599 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/AbstractActivity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/AbstractActivity.java @@ -2,8 +2,8 @@ package org.hibernate.envers.test.integration.inheritance.mixed.entities; import org.hibernate.envers.Audited; +import javax.persistence.EmbeddedId; import javax.persistence.Entity; -import javax.persistence.Id; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; @@ -11,19 +11,20 @@ import javax.persistence.InheritanceType; @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public abstract class AbstractActivity implements Activity { - @Id - private Integer id; + @EmbeddedId + private ActivityId id; + private Integer sequenceNumber; - public Integer getId() { + public ActivityId getId() { return id; } - public void setId(Integer id) { + public void setId(ActivityId id) { this.id = id; } - public Integer getSequenceNumber() { + public Integer getSequenceNumber() { return sequenceNumber; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/AbstractCheckActivity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/AbstractCheckActivity.java index 23205118ea..f34de1f5c3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/AbstractCheckActivity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/AbstractCheckActivity.java @@ -7,12 +7,15 @@ import javax.persistence.*; @Audited @Entity @DiscriminatorValue(value = "CHECK") -@SecondaryTable(name = "ACTIVITY_CHECK", pkJoinColumns = @PrimaryKeyJoinColumn(name = "ACTIVITY_ID")) +@SecondaryTable(name = "ACTIVITY_CHECK", + pkJoinColumns = {@PrimaryKeyJoinColumn(name = "ACTIVITY_ID"), + @PrimaryKeyJoinColumn(name = "ACTIVITY_ID2")}) public abstract class AbstractCheckActivity extends AbstractActivity { @Column(table = "ACTIVITY_CHECK") private Integer durationInMinutes; @ManyToOne(targetEntity = AbstractActivity.class, cascade = CascadeType.MERGE, fetch = FetchType.LAZY) - @JoinColumn(table = "ACTIVITY_CHECK") + @JoinColumns({@JoinColumn(table = "ACTIVITY_CHECK", referencedColumnName = "id"), + @JoinColumn(table = "ACTIVITY_CHECK", referencedColumnName = "id2")}) private Activity relatedActivity; public Integer getDurationInMinutes() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/Activity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/Activity.java index ff562333b5..ee35f3926f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/Activity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/Activity.java @@ -1,7 +1,9 @@ package org.hibernate.envers.test.integration.inheritance.mixed.entities; -public interface Activity { - Integer getId(); +import java.io.Serializable; + +public interface Activity extends Serializable { + ActivityId getId(); Integer getSequenceNumber(); } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/ActivityId.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/ActivityId.java new file mode 100644 index 0000000000..379df51381 --- /dev/null +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/ActivityId.java @@ -0,0 +1,53 @@ +package org.hibernate.envers.test.integration.inheritance.mixed.entities; + +import javax.persistence.Embeddable; +import java.io.Serializable; + +@Embeddable +public class ActivityId implements Serializable { + private Integer id; + private Integer id2; + + public ActivityId() { + } + + public ActivityId(int i, int i1) { + id = i; + id2 = i1; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getId2() { + return id2; + } + + public void setId2(Integer id2) { + this.id2 = id2; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return true; + } + if (!(obj instanceof ActivityId)) { + return false; + } + ActivityId id = (ActivityId) obj; + return getId().equals(id.getId()) && getId2().equals(id.getId2()); + } + + @Override + public int hashCode() { + int result = getId().hashCode(); + result = 31 * result + getId2().hashCode(); + return result; + } +} diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNaming.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNaming.java index 35befec1df..37cca396c6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNaming.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/JoinNaming.java @@ -33,6 +33,8 @@ import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Iterator; +import static junit.framework.Assert.*; + /** * @author Adam Warski (adam at warski dot org) */ @@ -122,16 +124,11 @@ public class JoinNaming extends AbstractEntityTest { @SuppressWarnings({"unchecked"}) @Test public void testJoinColumnName() { - Iterator columns = - getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.JoinNamingRefIngEntity_AUD") - .getProperty("reference").getColumnIterator(); - - while (columns.hasNext()) { - if ("jnree_column_reference".equals(columns.next().getName())) { - return; - } - } - - assert false; - } + Iterator columns = + getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.JoinNamingRefIngEntity_AUD") + .getProperty("reference_id").getColumnIterator(); + assertTrue(columns.hasNext()); + assertEquals("jnree_column_reference", columns.next().getName()); + assertFalse(columns.hasNext()); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNaming.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNaming.java index aaf38d6dde..9bbfab6338 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNaming.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinEmbIdNaming.java @@ -33,6 +33,8 @@ import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Iterator; +import static junit.framework.Assert.*; + /** * @author Adam Warski (adam at warski dot org) */ @@ -120,22 +122,18 @@ public class JoinEmbIdNaming extends AbstractEntityTest { @SuppressWarnings({"unchecked"}) @Test public void testJoinColumnNames() { - Iterator columns = - getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.ids.JoinEmbIdNamingRefIngEntity_AUD") - .getProperty("reference").getColumnIterator(); + Iterator columns = + getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.ids.JoinEmbIdNamingRefIngEntity_AUD") + .getProperty("reference_x").getColumnIterator(); + assertTrue(columns.hasNext()); + assertEquals("XX_reference", columns.next().getName()); + assertFalse(columns.hasNext()); - boolean xxFound = false; - boolean yyFound = false; - while (columns.hasNext()) { - if ("XX_reference".equals(columns.next().getName())) { - xxFound = true; - } + columns = getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.ids.JoinEmbIdNamingRefIngEntity_AUD") + .getProperty("reference_y").getColumnIterator(); - if ("YY_reference".equals(columns.next().getName())) { - yyFound = true; - } - } - - assert xxFound && yyFound; - } + assertTrue(columns.hasNext()); + assertEquals("YY_reference", columns.next().getName()); + assertFalse(columns.hasNext()); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNaming.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNaming.java index 5a290db418..4ca214c879 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNaming.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/naming/ids/JoinMulIdNaming.java @@ -33,6 +33,8 @@ import javax.persistence.EntityManager; import java.util.Arrays; import java.util.Iterator; +import static junit.framework.Assert.*; + /** * @author Adam Warski (adam at warski dot org) */ @@ -120,22 +122,17 @@ public class JoinMulIdNaming extends AbstractEntityTest { @SuppressWarnings({"unchecked"}) @Test public void testJoinColumnNames() { - Iterator columns = - getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.ids.JoinMulIdNamingRefIngEntity_AUD") - .getProperty("reference").getColumnIterator(); + Iterator columns = + getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.ids.JoinMulIdNamingRefIngEntity_AUD") + .getProperty("reference_id1").getColumnIterator(); + assertTrue(columns.hasNext()); + assertEquals("ID1_reference", columns.next().getName()); + assertFalse(columns.hasNext()); - boolean id1Found = false; - boolean id2Found = false; - while (columns.hasNext()) { - if ("ID1_reference".equals(columns.next().getName())) { - id1Found = true; - } - - if ("ID2_reference".equals(columns.next().getName())) { - id2Found = true; - } - } - - assert id1Found && id2Found; - } + columns = getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.ids.JoinMulIdNamingRefIngEntity_AUD") + .getProperty("reference_id2").getColumnIterator(); + assertTrue(columns.hasNext()); + assertEquals("ID2_reference", columns.next().getName()); + assertFalse(columns.hasNext()); + } } \ No newline at end of file diff --git a/hibernate-envers/src/test/resources/mappings/mixedInheritanceStrategies/mappingsPassing.hbm.xml b/hibernate-envers/src/test/resources/mappings/mixedInheritanceStrategies/mappingsJoinedSubclass.hbm.xml similarity index 66% rename from hibernate-envers/src/test/resources/mappings/mixedInheritanceStrategies/mappingsPassing.hbm.xml rename to hibernate-envers/src/test/resources/mappings/mixedInheritanceStrategies/mappingsJoinedSubclass.hbm.xml index a02f54aeeb..39e073a9f7 100644 --- a/hibernate-envers/src/test/resources/mappings/mixedInheritanceStrategies/mappingsPassing.hbm.xml +++ b/hibernate-envers/src/test/resources/mappings/mixedInheritanceStrategies/mappingsJoinedSubclass.hbm.xml @@ -7,15 +7,20 @@ - + + + - + - + + + + + - + + + + - + + + + diff --git a/hibernate-envers/src/test/resources/mappings/mixedInheritanceStrategies/mappingsFailing.hbm.xml b/hibernate-envers/src/test/resources/mappings/mixedInheritanceStrategies/mappingsMixed.hbm.xml similarity index 79% rename from hibernate-envers/src/test/resources/mappings/mixedInheritanceStrategies/mappingsFailing.hbm.xml rename to hibernate-envers/src/test/resources/mappings/mixedInheritanceStrategies/mappingsMixed.hbm.xml index f2908ac65e..e14438b1b8 100644 --- a/hibernate-envers/src/test/resources/mappings/mixedInheritanceStrategies/mappingsFailing.hbm.xml +++ b/hibernate-envers/src/test/resources/mappings/mixedInheritanceStrategies/mappingsMixed.hbm.xml @@ -7,9 +7,12 @@ - + + + + - + @@ -19,7 +22,10 @@ name="org.hibernate.envers.test.integration.inheritance.mixed.entities.AbstractCheckActivity" discriminator-value="CHECK"> - + + + + +