-
Notifications
You must be signed in to change notification settings - Fork 933
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix implied commits for Oracle and MySQL (#3485)
- Loading branch information
1 parent
2742b57
commit cd2e8ea
Showing
9 changed files
with
233 additions
and
21 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/NHibernate.Test/Async/NHSpecificTest/GH3474/Fixture.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,81 @@ | ||
//------------------------------------------------------------------------------ | ||
// <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.GH3474 | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class FixtureAsync : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
|
||
var e1 = new CreditCardPayment { CreditCardType = "Visa", Amount = 50 }; | ||
session.Save(e1); | ||
|
||
var e2 = new ChequePayment { Bank = "CA", Amount = 32 }; | ||
session.Save(e2); | ||
|
||
var e3 = new CashPayment { Amount = 18.5m }; | ||
session.Save(e3); | ||
|
||
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 PolymorphicUpdateShouldNotCommitAsync() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
var payment = await (session.Query<CreditCardPayment>().FirstAsync()); | ||
payment.Amount = 100; | ||
await (session.FlushAsync()); | ||
|
||
await (session.CreateQuery("update ChequePayment set Amount = 64").ExecuteUpdateAsync()); | ||
|
||
await (transaction.RollbackAsync()); | ||
} | ||
|
||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
IPayment payment = await (session.Query<CreditCardPayment>().FirstAsync()); | ||
Assert.That(payment.Amount, Is.EqualTo(50m)); | ||
|
||
payment = await (session.Query<ChequePayment>().FirstAsync()); | ||
Assert.That(payment.Amount, Is.EqualTo(32m)); | ||
|
||
await (transaction.CommitAsync()); | ||
} | ||
} | ||
} | ||
} |
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,30 @@ | ||
using System; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3474 | ||
{ | ||
public interface IPayment | ||
{ | ||
public Guid Id { get; set; } | ||
public decimal Amount { get; set; } | ||
} | ||
|
||
public class CreditCardPayment : IPayment | ||
{ | ||
public virtual Guid Id { get; set; } | ||
public virtual decimal Amount { get; set; } | ||
public virtual string CreditCardType { get; set; } | ||
} | ||
|
||
public class CashPayment : IPayment | ||
{ | ||
public virtual Guid Id { get; set; } | ||
public virtual decimal Amount { get; set; } | ||
} | ||
|
||
public class ChequePayment : IPayment | ||
{ | ||
public virtual Guid Id { get; set; } | ||
public virtual decimal Amount { get; set; } | ||
public virtual string Bank { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System.Linq; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3474 | ||
{ | ||
[TestFixture] | ||
public class Fixture : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
|
||
var e1 = new CreditCardPayment { CreditCardType = "Visa", Amount = 50 }; | ||
session.Save(e1); | ||
|
||
var e2 = new ChequePayment { Bank = "CA", Amount = 32 }; | ||
session.Save(e2); | ||
|
||
var e3 = new CashPayment { Amount = 18.5m }; | ||
session.Save(e3); | ||
|
||
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 PolymorphicUpdateShouldNotCommit() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
var payment = session.Query<CreditCardPayment>().First(); | ||
payment.Amount = 100; | ||
session.Flush(); | ||
|
||
session.CreateQuery("update ChequePayment set Amount = 64").ExecuteUpdate(); | ||
|
||
transaction.Rollback(); | ||
} | ||
|
||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
IPayment payment = session.Query<CreditCardPayment>().First(); | ||
Assert.That(payment.Amount, Is.EqualTo(50m)); | ||
|
||
payment = session.Query<ChequePayment>().First(); | ||
Assert.That(payment.Amount, Is.EqualTo(32m)); | ||
|
||
transaction.Commit(); | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/NHibernate.Test/NHSpecificTest/GH3474/Mappings.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,21 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" | ||
namespace="NHibernate.Test.NHSpecificTest.GH3474"> | ||
|
||
<class name="IPayment" table="Payment"> | ||
<id name="Id" generator="guid.comb" /> | ||
<property name="Amount" /> | ||
<joined-subclass name="CreditCardPayment"> | ||
<key column="Id" /> | ||
<property name="CreditCardType" /> | ||
</joined-subclass> | ||
<joined-subclass name="CashPayment"> | ||
<key column="Id"/> | ||
</joined-subclass> | ||
<joined-subclass name="ChequePayment"> | ||
<key column="Id"/> | ||
<property name="Bank" /> | ||
</joined-subclass> | ||
</class> | ||
|
||
</hibernate-mapping> |
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
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
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
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
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