-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for NullReferenceException in lazy bidirectional many-to-one prop…
…erties
- Loading branch information
David Uvenman
committed
Jun 24, 2024
1 parent
7729a58
commit f0747a3
Showing
5 changed files
with
102 additions
and
10 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
...ibernate.Envers.Tests/NetSpecific/Integration/ManyToOne/LazyProperty/Bidirectional/Car.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using NHibernate.Envers.Configuration.Attributes; | ||
|
||
namespace NHibernate.Envers.Tests.NetSpecific.Integration.ManyToOne.LazyProperty.Bidirectional | ||
{ | ||
[Audited] | ||
public class Car | ||
{ | ||
public virtual long Id { get; set; } | ||
public virtual int Number { get; set; } | ||
public virtual Person Owner { get; set; } | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...rs.Tests/NetSpecific/Integration/ManyToOne/LazyProperty/Bidirectional/LazyPropertyTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using SharpTestsEx; | ||
|
||
namespace NHibernate.Envers.Tests.NetSpecific.Integration.ManyToOne.LazyProperty.Bidirectional | ||
{ | ||
public partial class LazyPropertyBidirectionalTest : TestBase | ||
{ | ||
private long id_pers1; | ||
|
||
public LazyPropertyBidirectionalTest(AuditStrategyForTest strategyType) : base(strategyType) | ||
{ | ||
} | ||
|
||
protected override void Initialize() | ||
{ | ||
var pers1 = new Person {Name = "Hernan"}; | ||
|
||
using (var tx = Session.BeginTransaction()) | ||
{ | ||
id_pers1 = (long) Session.Save(pers1); | ||
tx.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void SavePersonProxyForFieldInterceptor() | ||
{ | ||
long carId; | ||
using (var tx = Session.BeginTransaction()) | ||
{ | ||
var pers = Session.Query<Person>().Single(x => x.Id == id_pers1); | ||
var car = new Car | ||
{ | ||
Owner = pers | ||
}; | ||
pers.Cars.Add(car); | ||
carId = (long) Session.Save(car); | ||
tx.Commit(); | ||
} | ||
|
||
AuditReader().Find<Car>(carId, 2).Owner.Name | ||
.Should().Be.EqualTo("Hernan"); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...Envers.Tests/NetSpecific/Integration/ManyToOne/LazyProperty/Bidirectional/Mapping.hbm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" | ||
assembly="NHibernate.Envers.Tests" | ||
namespace="NHibernate.Envers.Tests.NetSpecific.Integration.ManyToOne.LazyProperty.Bidirectional"> | ||
<class name="Person" table="DRIVERS"> | ||
<id name="Id" column="ID_PERSON" type="long"> | ||
<generator class="native"/> | ||
</id> | ||
<property name="Name" type="string" length="255" | ||
column="NAME" not-null="true" lazy="true"/> | ||
|
||
<set name="Cars" inverse="true" cascade="none"> | ||
<key column="person_id" /> | ||
<one-to-many class="Car" /> | ||
</set> | ||
</class> | ||
|
||
<class name="Car"> | ||
<id name="Id" column="ID_CAR" type="long"> | ||
<generator class="native"/> | ||
</id> | ||
<property name="Number" type="int" not-null="true" column="numb"/> | ||
<many-to-one name="Owner" class="Person" column="person_id"/> | ||
</class> | ||
</hibernate-mapping> |
13 changes: 13 additions & 0 deletions
13
...rnate.Envers.Tests/NetSpecific/Integration/ManyToOne/LazyProperty/Bidirectional/Person.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using NHibernate.Envers.Configuration.Attributes; | ||
using System.Collections.Generic; | ||
|
||
namespace NHibernate.Envers.Tests.NetSpecific.Integration.ManyToOne.LazyProperty.Bidirectional | ||
{ | ||
[Audited] | ||
public class Person | ||
{ | ||
public virtual long Id { get; set; } | ||
public virtual string Name { get; set; } | ||
public virtual ISet<Car> Cars { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters