Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Back ported fix to NH-1061 on trunk to 1.2.x branch.

SVN: branches/1.2.x@3078
  • Loading branch information...
commit 3160ad0956eb69cb807d83a0d3526f63cda3a6e5 1 parent 961eaf2
Karl Chu authored
View
38 src/NHibernate.Test/NHSpecificTest/NH1061/Fixture.cs
@@ -0,0 +1,38 @@
+using System.Reflection;
+using NHibernate.Cfg;
+using NHibernate.Id;
+using NHibernate.Mapping;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH1061
+{
+ [TestFixture]
+ public class Fixture // Not inheriting from BugTestCase on purpose
+ {
+ [Test]
+ public void IncrementGeneratorShouldIncludeClassLevelSchemaWhenGettingNextId()
+ {
+ System.Type thisType = this.GetType();
+ Assembly thisAssembly = thisType.Assembly;
+
+ Configuration cfg = new Configuration();
+ cfg.AddResource(thisType.Namespace + ".Mappings.hbm.xml", thisAssembly);
+
+ PersistentClass persistentClass = cfg.GetClassMapping(typeof(TestNH1061));
+ // We know the ID generator is an IncrementGenerator. The dialect does
+ // not play a big role here, so just use the MsSql2000Dialect.
+ IncrementGenerator generator = (IncrementGenerator)persistentClass.Identifier.CreateIdentifierGenerator(new NHibernate.Dialect.MsSql2000Dialect());
+
+ // I could not find a good seam to crack to test this.
+ // This is not ideal as we are reflecting into a private variable to test.
+ // On the other hand, the IncrementGenerator is rather stable, so I don't
+ // think this would be a huge problem.
+ // Having said that, if someone sees this and have a better idea to test,
+ // please feel free to change it.
+ FieldInfo sqlFieldInfo = generator.GetType().GetField("sql", BindingFlags.NonPublic | BindingFlags.Instance);
+ string sql = (string)sqlFieldInfo.GetValue(generator);
+
+ Assert.AreEqual("select max(Id) from test.TestNH1061", sql);
+ }
+ }
+}
View
12 src/NHibernate.Test/NHSpecificTest/NH1061/Mappings.hbm.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Test.NHSpecificTest.NH1061"
+ assembly="NHibernate.Test"
+>
+ <class name="TestNH1061" schema="test">
+ <id name="Id">
+ <generator class="increment"/>
+ </id>
+ <property name="Name"/>
+ </class>
+</hibernate-mapping>
View
21 src/NHibernate.Test/NHSpecificTest/NH1061/Model.cs
@@ -0,0 +1,21 @@
+using System.Collections;
+
+namespace NHibernate.Test.NHSpecificTest.NH1061
+{
+ public class TestNH1061
+ {
+ private int _Id;
+ public virtual int Id
+ {
+ get { return _Id; }
+ set { _Id = value; }
+ }
+
+ private string _Name;
+ public virtual string Name
+ {
+ get { return _Name; }
+ set { _Name = value; }
+ }
+ }
+}
View
5 src/NHibernate.Test/NHibernate.Test-2.0.csproj
@@ -221,6 +221,8 @@
<Compile Include="NHSpecificTest\BasicTimeFixture.cs" />
<Compile Include="NHSpecificTest\BugTestCase.cs" />
<Compile Include="NHSpecificTest\CollectionFixture.cs" />
+ <Compile Include="NHSpecificTest\NH1061\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH1061\Model.cs" />
<Compile Include="NHSpecificTest\NH1064\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1064\Model.cs" />
<Compile Include="NHSpecificTest\NH1119\Fixture.cs" />
@@ -922,6 +924,9 @@
<EmbeddedResource Include="NHSpecificTest\NH1064\Mappings.hbm.xml" />
</ItemGroup>
<ItemGroup>
+ <EmbeddedResource Include="NHSpecificTest\NH1061\Mappings.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
View
6 src/NHibernate/Cfg/HbmBinder.cs
@@ -1466,7 +1466,11 @@ private static void MakeIdentifier(XmlNode node, SimpleValue model, Mappings map
IDictionary parms = new Hashtable();
- if (mappings.SchemaName != null)
+ if (model.Table.Schema != null)
+ {
+ parms.Add("schema", model.Table.Schema);
+ }
+ else if (mappings.SchemaName != null)
{
parms.Add("schema", dialect.QuoteForSchemaName(mappings.SchemaName));
}
Please sign in to comment.
Something went wrong with that request. Please try again.