Skip to content

Test case and fix to NH-3898 #500

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
merged 6 commits into from
Nov 17, 2017
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
71 changes: 71 additions & 0 deletions src/NHibernate.Test/Async/NHSpecificTest/NH3898/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//------------------------------------------------------------------------------
// <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 NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.NH3898
{
using System.Threading.Tasks;
[TestFixture]
public class FixtureAsync : BugTestCase
{
protected override void Configure(Cfg.Configuration configuration)
{
configuration.SetProperty(Cfg.Environment.UseQueryCache, "false");
configuration.SetProperty(Cfg.Environment.UseSecondLevelCache, "false");
}

protected override void OnTearDown()
{
using (var s = OpenSession())
using (var tx = s.BeginTransaction())
{
s.CreateQuery("delete from Employee").ExecuteUpdate();

tx.Commit();
}
}

[Test]
public async Task GeneratedInsertUpdateTrueAsync()
{
object id;
using (var session = OpenSession())
using (var tx = session.BeginTransaction())
{
var employee = new Employee
{
Name = "Employee 1",
PromotionCount = 9999999
};
id = await (session.SaveAsync(employee));
await (tx.CommitAsync());
}

using (var session = OpenSession())
using (var tx = session.BeginTransaction())
{
var employee = await (session.GetAsync<Employee>(id));
Assert.That(employee.PromotionCount, Is.EqualTo(0));
employee.Name = "Employee 1 changed";
employee.PromotionCount++;
await (tx.CommitAsync());
}

using (var session = OpenSession())
using (session.BeginTransaction())
{
var employee = await (session.GetAsync<Employee>(id));
Assert.That(employee.Name, Is.EqualTo("Employee 1 changed"));
Assert.That(employee.PromotionCount, Is.EqualTo(1));
}
}
}
}
13 changes: 13 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3898/DomainClasses.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace NHibernate.Test.NHSpecificTest.NH3898
{
public class Employee
{
public virtual int Id { get; set; }

public virtual string Name { get; set; }

public virtual int PromotionCount { get; set; }
}
}
60 changes: 60 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3898/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.NH3898
{
[TestFixture]
public class Fixture : BugTestCase
{
protected override void Configure(Cfg.Configuration configuration)
{
configuration.SetProperty(Cfg.Environment.UseQueryCache, "false");
configuration.SetProperty(Cfg.Environment.UseSecondLevelCache, "false");
}

protected override void OnTearDown()
{
using (var s = OpenSession())
using (var tx = s.BeginTransaction())
{
s.CreateQuery("delete from Employee").ExecuteUpdate();

tx.Commit();
}
}

[Test]
public void GeneratedInsertUpdateTrue()
{
object id;
using (var session = OpenSession())
using (var tx = session.BeginTransaction())
{
var employee = new Employee
{
Name = "Employee 1",
PromotionCount = 9999999
};
id = session.Save(employee);
tx.Commit();
}

using (var session = OpenSession())
using (var tx = session.BeginTransaction())
{
var employee = session.Get<Employee>(id);
Assert.That(employee.PromotionCount, Is.EqualTo(0));
employee.Name = "Employee 1 changed";
employee.PromotionCount++;
tx.Commit();
}

using (var session = OpenSession())
using (session.BeginTransaction())
{
var employee = session.Get<Employee>(id);
Assert.That(employee.Name, Is.EqualTo("Employee 1 changed"));
Assert.That(employee.PromotionCount, Is.EqualTo(1));
}
}
}
}
14 changes: 14 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3898/Mappings.hbm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
namespace="NHibernate.Test.NHSpecificTest.NH3898">

<class name="Employee">
<id name="Id">
<generator class="native" />
</id>
<property name="Name"/>
<property name="PromotionCount" insert="false" generated="insert">
<column name="PromotionCount" default="0"/>
</property>
</class>
</hibernate-mapping>
18 changes: 7 additions & 11 deletions src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,23 +289,19 @@ private void BindValueProperty(HbmProperty propertyMapping, Property property)
throw new MappingException("cannot specify both insert=\"true\" and generated=\"" + generation
+ "\" for property: " + propertyMapping.Name);
}
else
{
property.IsInsertable = false;
}

property.IsInsertable = false;
}
if (generation == PropertyGeneration.Always)
{
// properties generated on update can never be updateable...
if (propertyMapping.updateSpecified && property.IsUpdateable && generation == PropertyGeneration.Always)
if (propertyMapping.updateSpecified && property.IsUpdateable)
{
// the user specifically supplied update="true",
// which constitutes an illegal combo
throw new MappingException("cannot specify both update=\"true\" and generated=\"" + generation
+ "\" for property: " + propertyMapping.Name);
}
else
{
property.IsUpdateable = false;
}
property.IsUpdateable = false;
}
}

Expand Down Expand Up @@ -421,4 +417,4 @@ private string GetPropertyAccessorName(string propertyMappedAccessor)
return propertyMappedAccessor ?? Mappings.DefaultAccess;
}
}
}
}