Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for problem with backreference with the same key name #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Src/NHibernate.Envers.Tests/NHibernate.Envers.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netCoreApp2.0;net461</TargetFrameworks>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using NHibernate.Envers.Configuration.Attributes;

namespace NHibernate.Envers.Tests.NetSpecific.Integration.ManyToMany.BackReference
{
[Audited]
public class BackReferenceEntity
{
public virtual long Id { get; set; }

public virtual OwningEntity Owning { get; set; }

public override bool Equals(object obj)
{
if (!(obj is BackReferenceEntity other))
return false;
return Id == other.Id;
}

public override int GetHashCode()
{
return Id.GetHashCode();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Collections.Generic;
using NUnit.Framework;

namespace NHibernate.Envers.Tests.NetSpecific.Integration.ManyToMany.BackReference
{
public class BackReferenceTest : TestBase
{
public BackReferenceTest(AuditStrategyForTest strategyType) : base(strategyType)
{
}

protected override IEnumerable<string> Mappings => new[] {"NetSpecific.Integration.ManyToMany.BackReference.Mapping.hbm.xml"};

protected override void Initialize()
{
}

[Test]
public void VerifySave()
{
using (var tx = Session.BeginTransaction())
{
var item = new BackReferenceEntity();

Session.Save(item);

var entity = new OwningEntity
{
Items = { item }
};

Session.Save(entity);

tx.Commit();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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.ManyToMany.BackReference">
<class name="OwningEntity">
<id name="Id" column="owning_id">
<generator class="native"/>
</id>
<bag name="Items" table="owning_item">
<key column="owning_id" />
<many-to-many class="BackReferenceEntity" column="item_id" />
</bag>
</class>
<class name="BackReferenceEntity">
<id name="Id" column="item_id">
<generator class="native"/>
</id>
<many-to-one name="Owning" class="OwningEntity" column="owning_id"/>
</class>
</hibernate-mapping>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Generic;
using NHibernate.Envers.Configuration.Attributes;

namespace NHibernate.Envers.Tests.NetSpecific.Integration.ManyToMany.BackReference
{
[Audited]
public class OwningEntity
{
public virtual long Id { get; set; }

public virtual IList<BackReferenceEntity> Items { get; protected set; } = new List<BackReferenceEntity>();

public override bool Equals(object obj)
{
if (!(obj is OwningEntity other))
return false;
return Id == other.Id;
}

public override int GetHashCode()
{
return Id.GetHashCode();
}
}
}