Commits

Roger Kratz committed 4f23dfc

fixed NHE-131

  • Participants
  • Parent commits dc89c18

Comments (0)

Files changed (7)

File Src/NHibernate.Envers.Tests/NHibernate.Envers.Tests.csproj

     <Compile Include="NetSpecific\Integration\Component\DerivedClassComponent.cs" />
     <Compile Include="NetSpecific\Integration\Component\DerivedClassOwner.cs" />
     <Compile Include="NetSpecific\Integration\Component\DerivedComponentTest.cs" />
+    <Compile Include="NetSpecific\Integration\Inheritance\Collection\Child.cs" />
+    <Compile Include="NetSpecific\Integration\Inheritance\Collection\ChildName.cs" />
+    <Compile Include="NetSpecific\Integration\Inheritance\Collection\CollectionItemWithNoAuditProperty.cs" />
+    <Compile Include="NetSpecific\Integration\Inheritance\Collection\Parent.cs" />
     <Compile Include="NetSpecific\Integration\RevInfo\Time\DateTimeTest.cs" />
     <Compile Include="NetSpecific\Integration\RevInfo\Time\LongTest.cs" />
     <Compile Include="NetSpecific\UnitTests\CustomLists\CustomListClasses.cs" />
     <Compile Include="ValidityTestBase.cs" />
   </ItemGroup>
   <ItemGroup>
+    <EmbeddedResource Include="NetSpecific\Integration\Inheritance\Collection\Mapping.hbm.xml" />
     <EmbeddedResource Include="NetSpecific\UnitTests\CustomLists\Mapping.hbm.xml" />
     <EmbeddedResource Include="NetSpecific\Entities\List.hbm.xml" />
     <EmbeddedResource Include="NetSpecific\Entities\Bag.hbm.xml" />

File Src/NHibernate.Envers.Tests/NetSpecific/Integration/Inheritance/Collection/Child.cs

+using System;
+using NHibernate.Envers.Configuration.Attributes;
+
+namespace NHibernate.Envers.Tests.NetSpecific.Integration.Inheritance.Collection
+{
+	[Audited]
+	public abstract class Child
+	{
+		public virtual Guid Id { get; set; }
+		[Audited(TargetAuditMode = RelationTargetAuditMode.NotAudited)]
+		public virtual ChildName Name { get; set; }
+		public abstract string Sex { get; }
+	}
+
+	[Audited]
+	public class Boy :Child
+	{
+		public override string Sex
+		{
+			get { return "Boy"; }
+		}
+	}
+
+	[Audited]
+	public class Girl:Child
+	{
+		public override string Sex
+		{
+			get { return "Girl"; }
+		}
+	}
+}

File Src/NHibernate.Envers.Tests/NetSpecific/Integration/Inheritance/Collection/ChildName.cs

+using System;
+
+namespace NHibernate.Envers.Tests.NetSpecific.Integration.Inheritance.Collection
+{
+	public class ChildName
+	{
+		public virtual Guid Id { get; set; }
+		public virtual string Name { get; set; }
+	}
+}

File Src/NHibernate.Envers.Tests/NetSpecific/Integration/Inheritance/Collection/CollectionItemWithNoAuditProperty.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Envers.Tests.NetSpecific.Integration.Inheritance.Collection
+{
+	[TestFixture]
+	public class CollectionItemWithNoAuditProperty : TestBase
+	{
+		private Guid parentId;
+
+		public CollectionItemWithNoAuditProperty(string strategyType) : base(strategyType)
+		{
+		}
+
+		protected override void Initialize()
+		{
+			var childName = new ChildName {Name = "the child"};
+			var parent = new Parent();
+			var boy = new Boy();
+			var girl = new Girl{Name = childName};
+			parent.Children = new List<Child> {boy};
+			using (var tx = Session.BeginTransaction())
+			{
+				Session.Save(childName);
+				parentId = (Guid) Session.Save(parent);
+				tx.Commit();
+			}
+			using (var tx = Session.BeginTransaction())
+			{
+				parent.Children.Add(girl);
+				tx.Commit();
+			}
+		}
+
+		[Test]
+		public void VerifyRevisionCount()
+		{
+			AuditReader().GetRevisions(typeof(Parent), parentId)
+				.Should().Have.SameSequenceAs(1, 2);
+		}
+
+		[Test]
+		public void VerifyHistory()
+		{
+			var ver1children = AuditReader().Find<Parent>(parentId, 1).Children;
+			var ver2children = AuditReader().Find<Parent>(parentId, 2).Children;
+
+			ver1children.Single().Sex.Should().Be.EqualTo("Boy");
+			ver2children[0].Sex.Should().Be.EqualTo("Boy");
+			ver2children[1].Sex.Should().Be.EqualTo("Girl");
+		}
+	}
+}

File Src/NHibernate.Envers.Tests/NetSpecific/Integration/Inheritance/Collection/Mapping.hbm.xml

+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+						 assembly="NHibernate.Envers.Tests"
+						 namespace="NHibernate.Envers.Tests.NetSpecific.Integration.Inheritance.Collection">
+	<class name="Parent">
+		<id name="Id">
+			<generator class="guid.comb"/>
+		</id>
+		<list name="Children" cascade="all-delete-orphan">
+			<key column="Parent" />
+			<index type="byte" column="OrderIndex"/>
+			<one-to-many class="Child"/>
+		</list>
+	</class>
+
+	<class name="Child" abstract="true">
+		<id name="Id">
+			<generator class="guid.comb"/>
+		</id>
+		<discriminator column="childtype"/>
+		<many-to-one name="Name"/>
+		
+		<subclass name="Boy" discriminator-value="1">
+		</subclass>
+		<subclass name="Girl" discriminator-value="2">
+		</subclass>
+	</class>
+	
+	<class name="ChildName">
+		<id name="Id">
+			<generator class="guid.comb"/>
+		</id>
+		<property name="Name"/>
+	</class>
+</hibernate-mapping>

File Src/NHibernate.Envers.Tests/NetSpecific/Integration/Inheritance/Collection/Parent.cs

+using System;
+using System.Collections.Generic;
+using NHibernate.Envers.Configuration.Attributes;
+
+namespace NHibernate.Envers.Tests.NetSpecific.Integration.Inheritance.Collection
+{
+	[Audited]
+	public class Parent
+	{
+		public virtual Guid Id { get; set; }
+		public virtual IList<Child> Children { get; set; }
+	}
+}

File Src/NHibernate.Envers/Entities/Mapper/Relation/ToOneIdMapper.cs

 					if (!referencedEntity.IsAudited)
 					{
 						var referencingEntityName = verCfg.EntCfg.GetEntityNameForVersionsEntityName((string) data["$type$"]);
-						ignoreNotFound = verCfg.EntCfg[referencingEntityName].GetRelationDescription(PropertyData.Name).IsIgnoreNotFound;
+						//not really correct if property is in base type
+						var relation = verCfg.EntCfg[referencingEntityName].GetRelationDescription(PropertyData.Name);
+						ignoreNotFound = relation != null && relation.IsIgnoreNotFound;
+						//
 					}
 					var persister = versionsReader.SessionImplementor.Factory.GetEntityPersister(_referencedEntityName);
 					var removed = RevisionType.Deleted.Equals(data[verCfg.AuditEntCfg.RevisionTypePropName]);