Skip to content

Test Case for Invalid SQL with property-ref on property using a formula #3309

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

Merged
Show file tree
Hide file tree
Changes from 5 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
70 changes: 70 additions & 0 deletions src/NHibernate.Test/Async/NHSpecificTest/GH3513/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//------------------------------------------------------------------------------
// <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;
using System.Linq;
using NUnit.Framework;
using NHibernate.Linq;

namespace NHibernate.Test.NHSpecificTest.GH3513
{
using System.Threading.Tasks;
[TestFixture]
public class FixtureAsync : BugTestCase
{
protected override void OnSetUp()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
var account = new Account { Id = 1, Name = "Account_1", OldAccountNumber = 1 };

var order = new HoldClose
{
Account = account,
CloseDate = new DateTime(2023, 1, 1)
};

session.Save(account);
session.Save(order);
transaction.Commit();
}
}

protected override void OnTearDown()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
// The HQL delete does all the job inside the database without loading the entities, but it does
// not handle delete order for avoiding violating constraints if any. Use
// session.Delete("from System.Object");
// instead if in need of having NHibernate ordering the deletes, but this will cause
// loading the entities in the session.
session.CreateQuery("delete from System.Object").ExecuteUpdate();

transaction.Commit();
}
}

[Test]
public async Task ManyToOneTargettingAFormulaAsync()
{
using (var session = OpenSession())
using (session.BeginTransaction())
{
var result = from e in session.Query<HoldClose>()
select e;

Assert.That(await (result.ToListAsync()), Has.Count.EqualTo(1));
}
}
}
}
9 changes: 9 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3513/Account.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NHibernate.Test.NHSpecificTest.GH3513
{
public class Account
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual int OldAccountNumber { get; set; }
}
}
58 changes: 58 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3513/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Linq;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH3513
{
[TestFixture]
public class Fixture : BugTestCase
{
protected override void OnSetUp()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
var account = new Account { Id = 1, Name = "Account_1", OldAccountNumber = 1 };

var order = new HoldClose
{
Account = account,
CloseDate = new DateTime(2023, 1, 1)
};

session.Save(account);
session.Save(order);
transaction.Commit();
}
}

protected override void OnTearDown()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
// The HQL delete does all the job inside the database without loading the entities, but it does
// not handle delete order for avoiding violating constraints if any. Use
// session.Delete("from System.Object");
// instead if in need of having NHibernate ordering the deletes, but this will cause
// loading the entities in the session.
session.CreateQuery("delete from System.Object").ExecuteUpdate();

transaction.Commit();
}
}

[Test]
public void ManyToOneTargettingAFormula()
{
using (var session = OpenSession())
using (session.BeginTransaction())
{
var result = from e in session.Query<HoldClose>()
select e;

Assert.That(result.ToList(), Has.Count.EqualTo(1));
}
}
}
}
11 changes: 11 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3513/HoldClose.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace NHibernate.Test.NHSpecificTest.GH3513
{
public class HoldClose
{
public virtual int Id { get; set; }
public virtual Account Account { get; set; }
public virtual DateTime CloseDate { get; set; }
}
}
18 changes: 18 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3513/Mappings.hbm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
namespace="NHibernate.Test.NHSpecificTest.GH3513">

<class name="HoldClose" >
<id name="Id" generator="native"/>
<many-to-one name="Account" class="Account" column="accountnumber" property-ref="OldAccountNumber"/>
<property name="CloseDate" />
</class>
<class name="Account" >
<id name="Id" generator="assigned"/>
<property name="Name"/>
<property name="OldAccountNumber" insert="false" update="false" generated="never" >
<formula>convert(int,substring([Oldaccountnumber],3,8))</formula>
</property>
</class>

</hibernate-mapping>