Skip to content

Commit b58353c

Browse files
whuthazzik
authored andcommitted
NH-3559 - Add column names quoting in UnionSubclassEntityPersister
1 parent 1cea336 commit b58353c

File tree

6 files changed

+119
-1
lines changed

6 files changed

+119
-1
lines changed

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,9 @@
11981198
<Compile Include="TypesTest\XDocTypeFixture.cs" />
11991199
<Compile Include="TypesTest\XmlDocClass.cs" />
12001200
<Compile Include="TypesTest\XmlDocTypeFixture.cs" />
1201+
<Compile Include="Unionsubclass\DatabaseKeyword.cs" />
1202+
<Compile Include="Unionsubclass\DatabaseKeywordBase.cs" />
1203+
<Compile Include="Unionsubclass\DatabaseKeywordsFixture.cs" />
12011204
<Compile Include="UtilityTest\ArrayHelperTests.cs" />
12021205
<Compile Include="UtilityTest\IdentitySetFixture.cs" />
12031206
<Compile Include="UtilityTest\EnumerableExtensionsTests\AnyExtensionTests.cs" />
@@ -2993,6 +2996,7 @@
29932996
<EmbeddedResource Include="NHSpecificTest\NH3392\Mappings.hbm.xml">
29942997
<SubType>Designer</SubType>
29952998
</EmbeddedResource>
2999+
<EmbeddedResource Include="Unionsubclass\DatabaseKeyword.hbm.xml" />
29963000
<EmbeddedResource Include="NHSpecificTest\NH2692\Mappings.hbm.xml">
29973001
<SubType>Designer</SubType>
29983002
</EmbeddedResource>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespace NHibernate.Test.Unionsubclass
2+
{
3+
public class DatabaseKeyword : DatabaseKeywordBase
4+
{
5+
private string table;
6+
private string create;
7+
private string view;
8+
private string user;
9+
10+
public virtual string Table
11+
{
12+
get { return table; }
13+
set { table = value; }
14+
}
15+
16+
public virtual string Create
17+
{
18+
get { return create; }
19+
set { create = value; }
20+
}
21+
22+
public virtual string View
23+
{
24+
get { return view; }
25+
set { view = value; }
26+
}
27+
28+
public virtual string User
29+
{
30+
get { return user; }
31+
set { user = value; }
32+
}
33+
}
34+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.Unionsubclass" default-access="field">
3+
<class name="DatabaseKeywordBase" abstract="true">
4+
5+
<id name="id" unsaved-value="0" column="id">
6+
<generator class="hilo">
7+
<param name="table">being_id</param>
8+
<param name="column">next_id</param>
9+
</generator>
10+
</id>
11+
12+
<union-subclass name="DatabaseKeyword" table="databaseKeywords">
13+
<property name="table" />
14+
<property name="create" />
15+
<property name="view" />
16+
<property name="user" />
17+
</union-subclass>
18+
</class>
19+
20+
</hibernate-mapping>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace NHibernate.Test.Unionsubclass
2+
{
3+
public abstract class DatabaseKeywordBase
4+
{
5+
private long id;
6+
7+
public virtual long Id
8+
{
9+
get { return id; }
10+
set { id = value; }
11+
}
12+
}
13+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using NHibernate.Cfg;
2+
using NUnit.Framework;
3+
using System.Collections;
4+
5+
namespace NHibernate.Test.Unionsubclass
6+
{
7+
[TestFixture]
8+
public class DatabaseKeywordsFixture : TestCase
9+
{
10+
protected override string MappingsAssembly
11+
{
12+
get { return "NHibernate.Test"; }
13+
}
14+
15+
protected override IList Mappings
16+
{
17+
get { return new string[] { "Unionsubclass.DatabaseKeyword.hbm.xml" }; }
18+
}
19+
20+
protected override void Configure(Configuration configuration)
21+
{
22+
base.Configure(configuration);
23+
24+
configuration.SetProperty(Environment.Hbm2ddlKeyWords, "auto-quote");
25+
}
26+
27+
[Test]
28+
public void UnionSubClassQuotesReservedColumnNames()
29+
{
30+
using (ISession s = OpenSession())
31+
using (ITransaction t = s.BeginTransaction())
32+
{
33+
s.Save(new DatabaseKeyword() { User = "user", View = "view", Table = "table", Create = "create" });
34+
35+
t.Commit();
36+
}
37+
38+
using (ISession s = OpenSession())
39+
using (ITransaction t = s.BeginTransaction())
40+
{
41+
s.Delete("from DatabaseKeywordBase");
42+
43+
t.Commit();
44+
}
45+
}
46+
}
47+
}

src/NHibernate/Persister/Entity/UnionSubclassEntityPersister.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ protected string GenerateSubquery(PersistentClass model, IMapping mapping)
332332
var sqlType = col.GetSqlTypeCode(mapping);
333333
buf.Append(dialect.GetSelectClauseNullString(sqlType)).Append(" as ");
334334
}
335-
buf.Append(col.Name);
335+
buf.Append(col.GetQuotedName(dialect));
336336
buf.Append(StringHelper.CommaSpace);
337337
}
338338
buf.Append(clazz.SubclassId).Append(" as clazz_");

0 commit comments

Comments
 (0)