diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/PassingJoinedSubclassInheritanceSessionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/JoinedSubclassInheritanceSessionTest.java
similarity index 88%
rename from hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/PassingJoinedSubclassInheritanceSessionTest.java
rename to hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/JoinedSubclassInheritanceSessionTest.java
index 29e6088188..565f500324 100644
--- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/PassingJoinedSubclassInheritanceSessionTest.java
+++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/JoinedSubclassInheritanceSessionTest.java
@@ -10,7 +10,7 @@ import java.net.URL;
/**
* @author Michal Skowronek (mskowr at o2 pl)
*/
-public class PassingJoinedSubclassInheritanceSessionTest extends AbstractInheritanceStrategiesSessionTest {
+public class JoinedSubclassInheritanceSessionTest extends AbstractInheritanceStrategiesSessionTest {
protected void initMappings() throws MappingException, URISyntaxException {
URL url = Thread.currentThread().getContextClassLoader().getResource(
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
new file mode 100644
index 0000000000..8ddbffa989
--- /dev/null
+++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesEntityTest.java
@@ -0,0 +1,137 @@
+package org.hibernate.envers.test.integration.inheritance.mixed;
+
+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;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Michal Skowronek (mskowr at o2 pl)
+ */
+public class MixedInheritanceStrategiesEntityTest extends AbstractEntityTest {
+
+ @Override
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(AbstractActivity.class);
+ cfg.addAnnotatedClass(AbstractCheckActivity.class);
+ cfg.addAnnotatedClass(CheckInActivity.class);
+ cfg.addAnnotatedClass(NormalActivity.class);
+ }
+
+ @Test
+ @Priority(10)
+ public void initData() {
+ NormalActivity normalActivity = new NormalActivity();
+ normalActivity.setId(1);
+ normalActivity.setSequenceNumber(1);
+
+ // Revision 1
+ getEntityManager().getTransaction().begin();
+
+ getEntityManager().persist(normalActivity);
+
+ getEntityManager().getTransaction().commit();
+ // Revision 2
+ getEntityManager().getTransaction().begin();
+
+ normalActivity = getEntityManager().find(NormalActivity.class, 1);
+ CheckInActivity checkInActivity = new CheckInActivity();
+ checkInActivity.setId(2);
+ checkInActivity.setSequenceNumber(0);
+ checkInActivity.setDurationInMinutes(30);
+ checkInActivity.setRelatedActivity(normalActivity);
+
+ getEntityManager().persist(checkInActivity);
+
+ getEntityManager().getTransaction().commit();
+
+ // Revision 3
+ normalActivity = new NormalActivity();
+ normalActivity.setId(3);
+ normalActivity.setSequenceNumber(2);
+
+ getEntityManager().getTransaction().begin();
+
+ getEntityManager().persist(normalActivity);
+
+ getEntityManager().getTransaction().commit();
+
+ // Revision 4
+ getEntityManager().getTransaction().begin();
+
+ normalActivity = getEntityManager().find(NormalActivity.class, 3);
+ checkInActivity = getEntityManager().find(CheckInActivity.class, 2);
+ checkInActivity.setRelatedActivity(normalActivity);
+
+ getEntityManager().merge(checkInActivity);
+
+ getEntityManager().getTransaction().commit();
+ }
+
+ @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));
+ }
+
+ @Test
+ public void testCurrentStateOfCheckInActivity() {
+
+ final CheckInActivity checkInActivity = getEntityManager().find(CheckInActivity.class, 2);
+ final NormalActivity normalActivity = getEntityManager().find(NormalActivity.class, 3);
+
+ assertEquals(2, checkInActivity.getId().intValue());
+ assertEquals(0, checkInActivity.getSequenceNumber().intValue());
+ assertEquals(30, checkInActivity.getDurationInMinutes().intValue());
+ final Activity relatedActivity = checkInActivity.getRelatedActivity();
+ assertEquals(normalActivity.getId(), relatedActivity.getId());
+ assertEquals(normalActivity.getSequenceNumber(), relatedActivity.getSequenceNumber());
+ }
+
+ @Test
+ public void testCheckCurrentStateOfNormalActivities() throws Exception {
+ final NormalActivity normalActivity1 = getEntityManager().find(NormalActivity.class, 1);
+ final NormalActivity normalActivity2 = getEntityManager().find(NormalActivity.class, 3);
+
+ assertEquals(1, normalActivity1.getId().intValue());
+ assertEquals(1, normalActivity1.getSequenceNumber().intValue());
+ assertEquals(3, normalActivity2.getId().intValue());
+ 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);
+
+ assertEquals(2, checkInActivity.getId().intValue());
+ assertEquals(0, checkInActivity.getSequenceNumber().intValue());
+ assertEquals(30, checkInActivity.getDurationInMinutes().intValue());
+ Activity relatedActivity = checkInActivity.getRelatedActivity();
+ assertEquals(normalActivity.getId(), relatedActivity.getId());
+ assertEquals(normalActivity.getSequenceNumber(), relatedActivity.getSequenceNumber());
+ }
+
+ @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);
+
+ assertEquals(2, checkInActivity.getId().intValue());
+ assertEquals(0, checkInActivity.getSequenceNumber().intValue());
+ assertEquals(30, checkInActivity.getDurationInMinutes().intValue());
+ Activity relatedActivity = checkInActivity.getRelatedActivity();
+ assertEquals(normalActivity.getId(), relatedActivity.getId());
+ assertEquals(normalActivity.getSequenceNumber(), relatedActivity.getSequenceNumber());
+ }
+
+}
diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/FailingMixedInheritanceStrategiesSessionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesSessionTest.java
similarity index 90%
rename from hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/FailingMixedInheritanceStrategiesSessionTest.java
rename to hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesSessionTest.java
index 570f5e7c77..d1d75a6fee 100644
--- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/FailingMixedInheritanceStrategiesSessionTest.java
+++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/MixedInheritanceStrategiesSessionTest.java
@@ -11,7 +11,7 @@ import java.net.URL;
/**
* @author Michal Skowronek (mskowr at o2 pl)
*/
-public class FailingMixedInheritanceStrategiesSessionTest extends AbstractInheritanceStrategiesSessionTest {
+public class MixedInheritanceStrategiesSessionTest extends AbstractInheritanceStrategiesSessionTest {
protected void initMappings() throws MappingException, URISyntaxException {
URL url = Thread.currentThread().getContextClassLoader().getResource(
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 11fe2baf53..c79380a1f6 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,16 @@ package org.hibernate.envers.test.integration.inheritance.mixed.entities;
import org.hibernate.envers.Audited;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
@Audited
+@Entity
+@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class AbstractActivity implements Activity {
+ @Id
private Integer id;
private Integer 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 be3a7abfc2..23205118ea 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
@@ -2,9 +2,17 @@ package org.hibernate.envers.test.integration.inheritance.mixed.entities;
import org.hibernate.envers.Audited;
+import javax.persistence.*;
+
@Audited
+@Entity
+@DiscriminatorValue(value = "CHECK")
+@SecondaryTable(name = "ACTIVITY_CHECK", pkJoinColumns = @PrimaryKeyJoinColumn(name = "ACTIVITY_ID"))
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")
private Activity relatedActivity;
public Integer getDurationInMinutes() {
diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/CheckInActivity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/CheckInActivity.java
index 76c5659b6e..71aaab3794 100644
--- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/CheckInActivity.java
+++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/CheckInActivity.java
@@ -2,7 +2,12 @@ package org.hibernate.envers.test.integration.inheritance.mixed.entities;
import org.hibernate.envers.Audited;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+
@Audited
+@Entity
+@DiscriminatorValue(value = "CHECK_IN")
public class CheckInActivity extends AbstractCheckActivity {
@Override
diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/NormalActivity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/NormalActivity.java
index 2f07dcd48f..c749506edb 100644
--- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/NormalActivity.java
+++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/inheritance/mixed/entities/NormalActivity.java
@@ -2,7 +2,12 @@ package org.hibernate.envers.test.integration.inheritance.mixed.entities;
import org.hibernate.envers.Audited;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+
@Audited
+@Entity
+@DiscriminatorValue(value = "NORMAL")
public class NormalActivity extends AbstractActivity {
@Override
diff --git a/hibernate-envers/src/test/resources/mappings/mixedInheritanceStrategies/mappingsFailing.hbm.xml b/hibernate-envers/src/test/resources/mappings/mixedInheritanceStrategies/mappingsFailing.hbm.xml
index e66ecfcc35..f2908ac65e 100644
--- a/hibernate-envers/src/test/resources/mappings/mixedInheritanceStrategies/mappingsFailing.hbm.xml
+++ b/hibernate-envers/src/test/resources/mappings/mixedInheritanceStrategies/mappingsFailing.hbm.xml
@@ -16,7 +16,8 @@
+ name="org.hibernate.envers.test.integration.inheritance.mixed.entities.AbstractCheckActivity"
+ discriminator-value="CHECK">