Skip to content
Merged
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
19 changes: 19 additions & 0 deletions releasenotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,25 @@ Release notes - NHibernate - Version 5.4.0
* #2242 Test case for NH-3972 - SQL error when selecting a column of a subclass when sibling classes have a column of the same name


Build 5.3.17
=============================

Release notes - NHibernate - Version 5.3.17

5 issues were resolved in this release.

** Bug

* #3306 Invalid SQL when referencing nullable entity in correlated subquery
* #3304 Fix SetSnapShot CopyTo variance failure
* #3294 Undefined join type failure with cross joins and Informix

** Task

* #3315 Release 5.3.17
* #3300 Backport handling of null DateTime parameters in Npgsql 6+


Build 5.3.16
=============================

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using System.Linq;
using NUnit.Framework;
using NHibernate.Linq;

namespace NHibernate.Test.NHSpecificTest.GH3306NullableEntityCorrelatedSubquery
{
using System.Threading.Tasks;
[TestFixture]
public class FixtureAsync : BugTestCase
{
private const string NAME_JOE = "Joe";
private const string NAME_ALLEN = "Allen";

protected override void OnSetUp()
{
using (var session = OpenSession())
using (var tx = session.BeginTransaction())
{
var joe = new Customer { Name = NAME_JOE };
session.Save(joe);

var allen = new Customer { Name = NAME_ALLEN };
session.Save(allen);

var joeInvoice0 = new Invoice { Customer = joe, Number = 0 };
session.Save(joeInvoice0);

var allenInvoice1 = new Invoice { Customer = allen, Number = 1 };
session.Save(allenInvoice1);

tx.Commit();
}
}

protected override void OnTearDown()
{
using (var session = OpenSession())
using (var tx = session.BeginTransaction())
{
session.Delete("from Invoice");
session.Delete("from Customer");
tx.Commit();
}
}

[Test]
public async Task NullableEntityInCorrelatedSubqueryAsync()
{
using (var s = OpenSession())
{
var customers = s.Query<Customer>().Where(c => c.Name == NAME_JOE);
var results = await (s.Query<Invoice>()
.Where(i => customers.Any(c => c.Invoices.Any(ci => ci.Customer == i.Customer))).ToListAsync());

Assert.That(results.Count, Is.EqualTo(1));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Linq;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH3306NullableEntityCorrelatedSubquery
{
[TestFixture]
public class Fixture : BugTestCase
{
private const string NAME_JOE = "Joe";
private const string NAME_ALLEN = "Allen";

protected override void OnSetUp()
{
using (var session = OpenSession())
using (var tx = session.BeginTransaction())
{
var joe = new Customer { Name = NAME_JOE };
session.Save(joe);

var allen = new Customer { Name = NAME_ALLEN };
session.Save(allen);

var joeInvoice0 = new Invoice { Customer = joe, Number = 0 };
session.Save(joeInvoice0);

var allenInvoice1 = new Invoice { Customer = allen, Number = 1 };
session.Save(allenInvoice1);

tx.Commit();
}
}

protected override void OnTearDown()
{
using (var session = OpenSession())
using (var tx = session.BeginTransaction())
{
session.Delete("from Invoice");
session.Delete("from Customer");
tx.Commit();
}
}

[Test]
public void NullableEntityInCorrelatedSubquery()
{
using (var s = OpenSession())
{
var customers = s.Query<Customer>().Where(c => c.Name == NAME_JOE);
var results = s.Query<Invoice>()
.Where(i => customers.Any(c => c.Invoices.Any(ci => ci.Customer == i.Customer))).ToList();

Assert.That(results.Count, Is.EqualTo(1));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernate.Test"
namespace="NHibernate.Test.NHSpecificTest.GH3306NullableEntityCorrelatedSubquery">

<class name="Customer" >
<id name="ID" type="Int32">
<generator class="native" />
</id>
<property name="Name" type="String" />

<set name="Invoices" inverse="true" >
<key column="CustomerID"/>
<one-to-many class="Invoice"/>
</set>
</class>

<class name="Invoice">
<id name="ID" type="Int32">
<generator class="native" />
</id>

<property name="Number" type="Int32" column="`Number`" />
<many-to-one name="Customer" not-found="ignore" column="CustomerID" class="Customer" />
</class>

</hibernate-mapping>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections.Generic;

namespace NHibernate.Test.NHSpecificTest.GH3306NullableEntityCorrelatedSubquery
{
public class Customer
{
public virtual int ID { get; protected set; }
public virtual ISet<Invoice> Invoices { get; set; }
public virtual string Name { get; set; }
}

public class Invoice
{
public virtual int ID { get; protected set; }
public virtual Customer Customer { get; set; }
public virtual int Number { get; set; }
}
}
28 changes: 27 additions & 1 deletion src/NHibernate.Test/UtilityTest/SetSnapShotFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System.Collections.Generic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using NHibernate.Collection.Generic.SetHelpers;
using NSubstitute.ExceptionExtensions;
using NUnit.Framework;

namespace NHibernate.Test.UtilityTest
Expand Down Expand Up @@ -70,6 +73,29 @@ public void TestCopyTo()
Assert.That(list, Is.EquivalentTo(array));
}

[Test]
public void TestCopyToObjectArray()
{
var list = new List<string> { "test1", null, "test2" };
ICollection sn = new SetSnapShot<string>(list);

var array = new object[3];
sn.CopyTo(array, 0);
Assert.That(list, Is.EquivalentTo(array));
}

[Test]
public void WhenCopyToIsCalledWithIncompatibleArrayTypeThenThrowArgumentOrInvalidCastException()
{
var list = new List<string> { "test1", null, "test2" };
ICollection sn = new SetSnapShot<string>(list);

var array = new int[3];
Assert.That(
() => sn.CopyTo(array, 0),
Throws.ArgumentException.Or.TypeOf<InvalidCastException>());
}

[Test]
public void TestSerialization()
{
Expand Down
30 changes: 24 additions & 6 deletions src/NHibernate/Collection/Generic/SetHelpers/SetSnapShot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,16 @@ IEnumerator IEnumerable.GetEnumerator()

void ICollection.CopyTo(Array array, int index)
{
if (!(array is T[] typedArray))
if (array is T[] typedArray)
{
throw new ArgumentException($"Array must be of type {typeof(T[])}.", nameof(array));
CopyTo(typedArray, index);
return;
}

CopyTo(typedArray, index);
if (_hasNull)
array.SetValue(default(T), index);
ICollection keysCollection = _values.Keys;
keysCollection.CopyTo(array, index + (_hasNull ? 1 : 0));
}

public int Count => _values.Count + (_hasNull ? 1 : 0);
Expand Down Expand Up @@ -153,12 +157,26 @@ protected SetSnapShot(SerializationInfo info, StreamingContext context) : base(i

void ICollection.CopyTo(Array array, int index)
{
if (!(array is T[] typedArray))
if (array is T[] typedArray)
{
throw new ArgumentException($"Array must be of type {typeof(T[])}.", nameof(array));
CopyTo(typedArray, index);
return;
}

CopyTo(typedArray, index);
if (array == null)
throw new ArgumentNullException(nameof(array));

if (index < 0)
throw new ArgumentOutOfRangeException(nameof(index), index, "Array index cannot be negative");

if (index > array.Length || Count > array.Length - index)
throw new ArgumentException("Provided array is too small", nameof(array));

foreach (var value in this)
{
array.SetValue(value, index);
index++;
}
}

bool ICollection.IsSynchronized => false;
Expand Down
3 changes: 3 additions & 0 deletions src/NHibernate/Dialect/InformixDialect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ public override JoinFragment CreateOuterJoinFragment()
return new InformixJoinFragment();
}

/// <inheritdoc />
public override bool SupportsCrossJoin => false;

/// <summary> The SQL literal value to which this database maps boolean values. </summary>
/// <param name="value">The boolean value </param>
/// <returns> The appropriate SQL literal. </returns>
Expand Down
5 changes: 1 addition & 4 deletions src/NHibernate/Dialect/InformixDialect0940.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,7 @@ public override JoinFragment CreateOuterJoinFragment()
return new ANSIJoinFragment();
}

/// <inheritdoc />
public override bool SupportsCrossJoin => false;

/// <summary>
/// <summary>
/// Does this Dialect have some kind of <c>LIMIT</c> syntax?
/// </summary>
/// <value>False, unless overridden.</value>
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Hql/Ast/ANTLR/Tree/DotNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ private void DereferenceEntity(EntityType entityType, bool implicitJoin, string
bool joinIsNeeded;

//For nullable entity comparisons we always need to add join (like not constrained one-to-one or not-found ignore associations)
bool comparisonWithNullableEntity = entityType.IsNullable && Walker.IsComparativeExpressionClause;
bool comparisonWithNullableEntity = entityType.IsNullable && Walker.IsComparativeExpressionClause && !IsCorrelatedSubselect;

if ( IsDotNode( parent ) )
{
Expand Down